Jump to content
Sign in to follow this  
nAutoIT

General Question about TimerInit()

Recommended Posts

nAutoIT

Function Reference

TimerInit

--------------------------------------------------------------------------------

Returns a timestamp (in milliseconds).

$time1 = TimerInit()
sleep(3000)
$time2 = TimerInit()
MsgBox(1,"",$time1 & @CRLF & $time2 & @CRLF & TimerDiff($time1) & @CRLF & TimerDiff($time1 + 5000000))

MsgBox:

21810363484

21821059638

2988.2644302558

1591.46427828118

TimerInit returns a timestamp in 0.0003 milliseconds?

Is Sleep() or TimerDiff() inaccurate?

Share this post


Link to post
Share on other sites
monoscout999

the diff is about 2988.2644302558?? you want to be more accurate than that?

This don`t seems to be correct.. but i am not sure.

TimerDiff($time1 + 5000000)

The _TimeInit() function from the timer.au3 library "Retrieves the current value of the high-resolution performance counter." acourding MSDN

Edited by monoscout999

Share this post


Link to post
Share on other sites
Melba23

nAutoIT,

I am not quite sure what you are trying to prove with that. Remember that AutoIt is an interpreted language so that it takes a finite time to parse each line when it is needed. Plus your CPU may or may not be busy at the very moment you try to get the timestamp or measure the Sleep.

Here is a small script which shows a couple of variants on TimerDiff to show how little they differ:

$iDelay = 3000
ConsoleWrite("Running!" & @CRLF)

For $i = 1 To 5

    ; Here we get the time difference first and then display it
    $iTime = TimerInit()
    Sleep($iDelay)
    $nDiff = TimerDiff($iTime)
    ConsoleWrite("Diff first: " & $nDiff & @CRLF)

    ; Here we get the time difference while we display it
    $iTime = TimerInit()
    Sleep($iDelay)
    ConsoleWrite("Diff last: " & TimerDiff($iTime) & @CRLF)

Next

When I run this I get values betwen 3000.10ms and 3004.05ms - good enough for me. Can you detect 4ms? :)

Basically TimerInit/TimerDiff and Sleep are more than accurate enough for humans and pretty accurate for computers. :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
nAutoIT

A 14 digit number isn't very accurate if the last 12 digits are wrong, based on the presumption that Sleep(3000) delays for >=3000ms.

TimerDiff being accurate to 0.1 Seconds is ok for my needs, just beeing curious.

Share this post


Link to post
Share on other sites
nAutoIT

I am not trying to prove anything, i try to understand the results i got. I was surprised, that the TimerDiff is <3000ms, so i wondered if Sleep, or TimerDiff is causing it. If i understand your indirect answer correctly, it could be both.

The more important thing for me is: Is the Function Reference wrong, or do i not get it?

Dont want to sound rude or anything, English isnt my first language. Just asking out of curiosity.

Share this post


Link to post
Share on other sites
nAutoIT

Your script returns this:

Running!

Diff first: 3007.44088983376

Diff last: 3007.67835018138

Diff first: 3007.72640098113

Diff last: 3007.7107565347

Diff first: 3007.71997558349

Diff last: 3007.72137240906

Diff first: 3007.72528352067

Diff last: 3007.71746129746

Diff first: 3007.72081367883

Diff last: 3007.72081367883

Any insight why my approach yields less comprehensible results?

Share this post


Link to post
Share on other sites
monoscout999

what is wrong with the function reference? as melba23 says autoit is an interpreted languaje and it takes a time to read the lines... in your example the error is about 12 ms, maybe too much, but still tolerable, if you want to be more accurate then you should run your script with higher priority and try to not overload the CPU usage while the script is running, but personaly to me 12 ms is nothing.

EDIT:

Your script returns this:

Running!

Diff first: 3007.44088983376

Diff last: 3007.67835018138

Diff first: 3007.72640098113

Diff last: 3007.7107565347

Diff first: 3007.71997558349

Diff last: 3007.72137240906

Diff first: 3007.72528352067

Diff last: 3007.71746129746

Diff first: 3007.72081367883

Diff last: 3007.72081367883

Any insight why my approach yields less comprehensible results?

Depends the CPU usage of that moment. Edited by monoscout999

Share this post


Link to post
Share on other sites
Melba23

nAutoIT,

I assume that last post is directed at me. :)

First, your English is fine. :mellow:

Second, as I tried to point out, AutoIt is not the language of choice if you want really accurate timings. For example, a Sleep with a parameter of 1-9 will still pause for 10ms. :)

TimerDiff being accurate to 0.1 Seconds is ok for my needs

In which case you shoudl have no problems at all. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
nAutoIT

what is wrong with the function reference?

The function reference states, that TimerInit returns a timestamp in Milliseconds.

If you compare $time1 and $time2, there is not 3000ms difference.

Also TimerDiff($time1 + 5000000) results in reducing the time by ~1500ms.

In which case you shoudl have no problems at all. :)

Not with my code, but with not understanding. Guess im just naturally curious. :mellow:

Share this post


Link to post
Share on other sites
Melba23

nAutoIT,

The time in ms is calculated when you use TimerDiff on the value returned by an intial TimerInit, as the example for TimerInit in the Help file clearly shows. TimerInit merely gives you a timestamp - obviously not in ms because when you call it you have not started timing, so how can it measure anything? :)

Does that satisfy your curiosity? :mellow: Becasue you have certainly exhausted my patience.

If you are still not happy with the Help file description, could I suggest that you make a suggest for an alternative wording here.

M23

P.S. And adding a value to a TimerInit timestamp will not do what you think it does - which is why I said at the beginning of all this I was unsure what you were trying to prove. :)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
MvGulik

1) "TimerInit"..."Returns a timestamp (in milliseconds)." is just a bug in the Doc. (aka: old doc or something like that.) (already covered I see.)

2) What TimerInit() returns depends on the hardware(CPU). (think I had a link to something in relation to this, but need to look it up.)

n) Generally timing things around 10..1 milliseconds.

---

link: www.gamedev.net/forum ... Why the "QueryPerformanceFrequency" gives the poor performance in windows7

Not sure if it makes sens ... it did back than.

Edited by iEvKI3gv9Wrkd41u

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites
MvGulik

I believe it is a timestamp (indeed in milliseconds) from a certain point in time.

When that time is, I have no Idea.

Anyting that's measuring something that's in some way related to a time-period can be called a timestamp. :mellow:

Its some CPU related tick count. Where u use the "QueryPerformanceFrequency" to normalize it to a time in miliseconds. (see Au3 Timers.au3 UDF)

Start point is Computer restart/bootup.


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites
JohnOne

So that's where it comes from eh.

Of course you are right, anything can be called a time stamp, and that's what the help file calls it.

And seeing as how that time stamp depicts the number of milliseconds from that point in time then I believe the help file is not a mistake to call it that.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
MvGulik

lol. Your sure where talking about the same things here.

Anywaaaay. Doc can stay the way it is. I don't mind topics like these. I just don't agree with what the doc is saying. :mellow:


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
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
Sign in to follow this  

×