Jump to content

TimerDiff returns with very large offset


Recommended Posts

Hi.

You missed the () after TimerInit. Then give it another try.

Regards, Conrad

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Link to comment
Share on other sites

As we can see in your console output the numbers are very big but each with a difference round about 1000ms.

Maybe someone can explain how the init would have been set nearly 99799 seconds (or 27,7 hours) ago. 

Conrad

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Link to comment
Share on other sites

Try this:

For $i = 0 to 10
    ConsoleWrite(TimerDiff(Default)&@LF)
    Sleep(1000)
Next

Output should be next to your first posted code. So something inside TimerDiff() seems to look to some internal everlasting clock. Can someone explain this?

Conrad

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Link to comment
Share on other sites

Works for me after adding the brackets/parenthesis after TimerInit:

0.011973808149944
1004.30429893923
2009.74953074076
3019.25103259841
4019.33998088752
5019.45743824366
6028.8517460093
7034.04780856504
8042.60680066688
9048.60396800598
10053.0570842751

 

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

By the way:

Local $timer
$timer = TimerInit()
ConsoleWrite($timer & @CRLF & @CRLF)
For $i = 0 to 3
    ConsoleWrite((TimerDiff(Default)) & @CRLF)
    Sleep(1000)
Next
5594216671992

559421667.2591
559422680.1801
559423694.0777
559424708.1486

So $timer is set to the "clock" in nanoseconds. And TimerDiff($timer) is just the difference. But what is the clock?

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Link to comment
Share on other sites

3 hours ago, Simpel said:

By the way:

Local $timer
$timer = TimerInit()
ConsoleWrite($timer & @CRLF & @CRLF)
For $i = 0 to 3
    ConsoleWrite((TimerDiff(Default)) & @CRLF)
    Sleep(1000)
Next
5594216671992

559421667.2591
559422680.1801
559423694.0777
559424708.1486

So $timer is set to the "clock" in nanoseconds. And TimerDiff($timer) is just the difference. But what is the clock?

TimerDiff is based on The "QueryPerformanceCounter", and "QueryPerformanceFrequency" Windows APIs. Performance frequency depends on CPU speed, and the counter starts at boot. Here's an example using functions from Timers.au3 UDF that directly call those Windows API

$hTimerInternal = TimerInit()
$hTimerUDF = _Timer_Init()
ConsoleWrite("Internal Init: " & $hTimerInternal & @CRLF)
ConsoleWrite("UDF Init     : " & $hTimerUDF & @CRLF & @CRLF)

Sleep(1000)

ConsoleWrite("Internal Diff: " & TimerDiff($hTimerInternal) & @CRLF)
ConsoleWrite("UDF Diff     : " & _Timer_Diff($hTimerUDF) & @CRLF & @CRLF)

$hTimerUDF2 = _Timer_Init()
$iTimerfreq = __Timer_QueryPerformanceFrequency()
ConsoleWrite("UDF Time 2   : " & $hTimerUDF2 & @CRLF)
ConsoleWrite("Perf Freq    : " & $iTimerfreq & @CRLF)
ConsoleWrite("1000 * (" & $hTimerUDF2 & " - " & $hTimerUDF & ")/" & $iTimerfreq & " = " & 1000 * ($hTimerUDF2 - $hTimerUDF) / $iTimerfreq & @CRLF&@CRLF)

$iUptimeSeconds=$hTimerUDF2 / $iTimerfreq
ConsoleWrite("Uptime Seconds: "&$iUptimeSeconds&@CRLF)

;Functions from Timers.au3 UDF
Func __Timer_QueryPerformanceCounter()
    Local $aResult = DllCall("kernel32.dll", "bool", "QueryPerformanceCounter", "int64*", 0)
    If @error Then Return SetError(@error, @extended, -1)
    Return SetExtended($aResult[0], $aResult[1])
EndFunc   ;==>__Timer_QueryPerformanceCounter

Func __Timer_QueryPerformanceFrequency()
    Local $aResult = DllCall("kernel32.dll", "bool", "QueryPerformanceFrequency", "int64*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetExtended($aResult[0], $aResult[1])
EndFunc   ;==>__Timer_QueryPerformanceFrequency

Func _Timer_Diff($iTimeStamp)
    Return 1000 * (__Timer_QueryPerformanceCounter() - $iTimeStamp) / __Timer_QueryPerformanceFrequency()
EndFunc   ;==>_Timer_Diff

Func _Timer_Init()
    Return __Timer_QueryPerformanceCounter()
EndFunc   ;==>_Timer_Init

The output I get is:

Internal Init: 977233559322
UDF Init     : 977233559410

Internal Diff: 996.996298670489
UDF Diff     : 997.127965359638

UDF Time 2   : 977236960227
Perf Freq    : 3410126
1000 * (977236960227 - 977233559410)/3410126 = 997.270188843462

Uptime Seconds: 286569.164959594

286569 seconds is 3.32 days, which matches my system uptime.

Link to comment
Share on other sites

Thanks @TurionAltec.

@Yamakawa : I know. Should only show what else seems to be valid. (What it isn't.)

Conrad

Edited by Simpel
SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Link to comment
Share on other sites

Hi,

there is a correlation between the Clockticks of the CPU (can be read by RDTSC) and the Autoit-TimerInit()-Function....

;RDTSC returns the clockticks since computer start in EDX:EAX
$struct = DllStructCreate("byte[3]")                           ;reserve memory
DllStructSetData($struct, 1, "0x0F31C3")                       ;RDTSC and RET into memory


;testroutine correlation between RDTSC and TimerInit()
$ret = DllCallAddress("uint:cdecl", DllStructGetPtr($struct))  ;call memory returns colockticks in EAX
$rdtsc_old = $ret[0]                                           ;get clockticks in EAX
$t_old = TimerInit()

For $i = 1 To 10

    $ret = DllCallAddress("uint:cdecl", DllStructGetPtr($struct)) ;call memory returns clockticks in EAX
    $t = TimerInit()
    $rdtsc = $ret[0]                                           ;get clockticks in EAX

    ConsoleWrite("delta RDTSC = " & Int(($rdtsc - $rdtsc_old) / 1000) & @CRLF) ;difference RDTSC
    ConsoleWrite("delta Timer = " & $t - $t_old & @CRLF & @CRLF) ;difference TimerInit()

    $rdtsc_old = $rdtsc
    $t_old = $t

Next

 

Edited by AndyG
Link to comment
Share on other sites

Oh, getting this:

Error.PNG

Conrad

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Link to comment
Share on other sites

In the original code posted, $timer wasn't being assigned the VALUE of the return from TimerInit, it was creating a reference to the FUNCTION TimerInit. So every time that TimerDiff was being called, it was also calling the FUNCTION TimerInit, rather than the handle that the function returns. I don't know how TimerDiff works internally, but this misuse of the reference to the function, rather than the return from the function is bound to cause some idiosyncrasies.

Local $timer
$timer = TimerInit ; Original code
ConsoleWrite("$timer is " & (Isfunc($timer) ?"a ": "not a ") & "function"& @lf)
$timer = TimerInit() ; Corrected code
ConsoleWrite("$timer is " & (Isfunc($timer) ?"a ": "not a ") & "function"& @lf)
For $i = 0 To 10
    ConsoleWrite(TimerDiff($timer) & @LF)
    Sleep(1000)
Next

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@Simpel (was ein Name... :o)  )

habe die erste Zeile vergessen zu kopieren , did lost the first line while copy/paste

#AutoIt3Wrapper_UseX64=n   ;32-Bit mode

(original code in post#11 edited)

Edited by AndyG
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...