Jump to content

Problem with TimerInit and TimerDiff


 Share

Recommended Posts

Hi everyone :P

Well, so here's my problem:

Timerinit() returns a timestamp, to me it seems a strange timestamp, lookie here: 706'850'139'146'652 (digit grouping added for emphasis), now, since the function states it returns a timestamp in milliseconds, I would assume we are talking about something in the region of 22'414 years worth of milliseconds... however, a bit later the timestamp is now 727'289'493'116'814, and the diff between those two is 6'799'518.94773952. okay, so it's not actually 22'414 years, but 2 hours, which means the timestamp returned is NOT in milliseconds but in 10s of nanoseconds (if I counted correctly). Now, I don't know about your machine and OS, but mine is not even remotely capable of timings this accurate.

I just thought of a funny use... measure the time loss of a certain procedure:

this code:

Global $a[3]
$c=Timerinit()
$c1=Timerinit()
$c2=Timerinit()
_log($c)
_log($c1)
_log($c2)
For $b=1 to 3
    $a[$b]=timerinit()
Next
For $b=1 to 3
    _log($a[$b])
Next
For $b=1 to 3
    _log(Timerinit())
Next
Func _Log($text)
    $file = FileOpen(@ScriptDir & "\log2.txt", 1)
    FileWriteLine($file, $text)
    FileClose($file)
EndFunc  ;==>_Log

Produces this:

9242865200448
9242865208206
9242865211410

9242866757412
9242866762038
9242866765602

9242867654415
9242867881575
9242868156408

Which could teach us that, if we required something to go off at a precision of ~60 microseconds, arrays are fine, no visible difference to normal variables (oh, a for loop aswell), but stay away from opening, writing to and closing files!

Sooo... thats one part of the timerinit thing I never liked, seriously, millisecond accuracy is more than enough!

However, my real problem is this: Timerinit() seems to restart/go fubar if you reboot your machine, since I have a script which writes timerinits to .ini files, reboots, rereads them and then comes up with: 748096569011160 (before reboot), 9406684172880 (after reboot) and -245738484.648802 (the difference), this is a problem if it waits for a difference of 6835000.

Now, I know my options are to calculate the seconds myself (which would be accurate enough for my purposes... hell, minutes would be!), using @year @yday @hour @min and @sec, but... you know, couldn't we change the Timerinit() to 1) milliseconds and 2) Time difference between the now and.. 1 Jan 2000 for example?

As far as I can see, as long as we change TimerDiff() along with it to expect milliseconds instead of 1/100ths of microseconds no changes in any existing scripts would be required and it should stay backwards compatible.

The drawback of course would be that we no longer get such an exact readout...

I hope I don't come over wrong, this should be a kind of suggestion, or make you think, or even smile for a few seconds, not an OMGBBQWTF-rant :P

Oh, I should add that I found nothing in bug reports, and well, I don't consider this a bug, merely a ... flaw, if you will, so I'd first like to hear some input, and I'd more than happily fill out a bug tracking thingy if the responses are positive :o

Kind regards,

Miranda

Link to comment
Share on other sites

  • Moderators

If you want to read up on how TimerInit() works, http://msdn.microsoft.com/en-us/library/ms644904(VS.85).aspx , you'll need to understand how that works first. (You'll see that it is basically a counter from the time that the system was rebooted.)

So you'll see that TimerInit() works exactly how it should, and how many other languages in fact use it as well.

Edit:

*Had a thought*

If something like that is that important to you, I'd do my homework maybe on how to retrieve the bios time, which wouldn't reset on reboot.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hey Smoke :P

Thanks for your answer...

I do understand how timerinit works. Or rather, I didn't at first, and I looked at what was happening and the numbers I got, and I realized how it worked :P (and the resolution returned made me understand that this is an "external" function... I've run into timers on windows and problems with them when I had some SERIOUS DPC Latency trouble)

Also, I do not doubt that it is working as intended, nor do I doubt that many other languages use it like this, but I was trying to point out (from a pure user standpoint of view, I'm not a dev at any rate, merely an autoit scripter), that the way it works doesn't make much sense, since, imho there is a much simpler alternative of calculating the ms since a certain date.

Hmm, and no, this has been a bit of a peeve to me since I started scripting autoit, yet this instance is the very first time that I'm actually having trouble with it, instead of just being annoyed by the way it works :o, yet, like I said, I can code around it without much trouble, so there's no need to... bios time? oh boy :D Simply windows time difference to a certain date in the past would be idea imho.

So, this was simply a "I don't like how it works, and have a suggestion as to how it should work, and would like to hear other peoples opinions" kind of thread... :zorro:

Kind regards,

Miranda

Edit: Spelling, Logic, etc. :robot:

Edited by Miranda
Link to comment
Share on other sites

  • Moderators

Hey Smoke :P

Thanks for your answer...

I do understand how timerinit works. Or rather, I didn't at first, and I looked at what was happening and the numbers I got, and I realized how it worked :o (and the resolution returned made me understand that this is an "external" function... I've run into timers on windows and problems with them when I had some SERIOUS DPC Latency trouble)

Also, I do not doubt that it is working as intended, nor do I doubt that many other languages use it like this, but I was trying to point out (from a pure user standpoint of view, I'm not a dev at any rate, merely an autoit scripter), that the way it works doesn't make much sense, since, imho there is a much simpler alternative of calculating the ms since a certain date.

Hmm, and no, this has been a bit of a peeve to me since I started scripting autoit, yet this instance is the very first time that I'm actually having trouble with it, instead of just being annoyed by the way it works :D, yet, like I said, I can code around it without much trouble, so there's no need to... bios time? oh boy :zorro: Simply windows time difference to a certain date in the past would be idea imho.

So, this was simply a "I don't like how it works, and have a suggestion as to how it should work, and would like to hear other peoples opinions" kind of thread... :robot:

Kind regards,

Miranda

Edit: Spelling, Logic, etc. :dance:

Ahh, then I'll move your post to the official Devs bitch section since it wasn't a question for support or a lack of undestanding :dance::P

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Ahh, then I'll move your post to the official Devs bitch section since it wasn't a question for support or a lack of undestanding :o:P

Thanks alot!

I was a bit afraid to post here, since I'm not really experienced or established enough :P

Link to comment
Share on other sites

Thanks for that link, rather informative...

What do you have to say on the subject, should timerinit be changed to allow storing and reloading after boot, or is it handy as a counter to find out the time since last boot?

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...