Sign in to follow this  
Followers 0
nullschritt

getting microseconds

19 posts in this topic

Hello, am coding in autoit, and am using timestamps to process information. Sorry I can't go into too much detail about what exactly I'm doing. Nothing harmful though (:

Was wondering if there was a way to get how many microsecond past the current millisecond we are?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

?

TimerInit() & TimerDiff()

Edited by PincoPanco

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

nullscritt,

Checkout _winapi_queryperformancefrequency and _winapi_queryperformancecounter...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

An old, but very interesting, thread might also be worth a read:

Edited by czardas

Share this post


Link to post
Share on other sites

nullscritt,

Checkout _winapi_queryperformancefrequency and _winapi_queryperformancecounter...

How do I convert the returned result into a timestamp?

Share this post


Link to post
Share on other sites

An old, but very interesting, thread might also be worth a read:

Thanks but I need to get the system time to an accuracy of microseconds. Having the ability to preform operations down to nano seconds, and getting the number of nanoseconds elapsed are two different things.

Unless I wrote a function to start a nanosecond timer every time @msec updated and get the value of the timer any time I wanted nanoseconds, but this would be extremely resource intensive, perhaps there's a simpler way, but every way I can think of requires some form of checking at least once per microsecond, that's a million times a second(I don't think autoit could even keep up with a single thread)!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Good luck with that, just do something like this, and you will see that anything smaller than milliseconds is not feasible.

Run this, and that is basically as fast as you can go:

$iTime = TimerInit()
ConsoleWrite(TimerDiff($iTime) & @CRLF)
$iTime = TimerInit()
ConsoleWrite(TimerDiff($iTime) & @CRLF)
$iTime = TimerInit()
ConsoleWrite(TimerDiff($iTime) & @CRLF)
$iTime = TimerInit()
ConsoleWrite(TimerDiff($iTime) & @CRLF)
$iTime = TimerInit()
ConsoleWrite(TimerDiff($iTime) & @CRLF)
$iTime = TimerInit()
ConsoleWrite(TimerDiff($iTime) & @CRLF)
$iTime = TimerInit()
ConsoleWrite(TimerDiff($iTime) & @CRLF)
$iTime = TimerInit()
ConsoleWrite(TimerDiff($iTime) & @CRLF)
$iTime = TimerInit()
ConsoleWrite(TimerDiff($iTime) & @CRLF)
$iTime = TimerInit()
ConsoleWrite(TimerDiff($iTime) & @CRLF)
$iTime = TimerInit()
ConsoleWrite(TimerDiff($iTime) & @CRLF)

My comp is fairly fast, output:

0.00159901602949609
0.000639606411798436
0.000639606411798436
0.000639606411798436
0.000639606411798436
0.000639606411798436
0.000639606411798436
0.000639606411798436
0.000639606411798436
0.000319803205899218
0.000319803205899218

My work comp would probably be 1 millisecond each

or, something like this:

$iTime = TimerInit()
While TimerDiff($iTime)<1000
    $i+=1
WEnd
ConsoleWrite($i & @CRLF)

My output: 1461040...but that's doing simple actions each loop.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

kylomas has given the answer, you just need to research how to do whatever it is you're trying to do using the information those 2 functions give to you.


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

Share this post


Link to post
Share on other sites

kylomas has given the answer, you just need to research how to do whatever it is you're trying to do using the information those 2 functions give to you.

Have been searching around, haven't found any examples that I understand, as far as I can tell, this set of functions is used like a high precision timer.....

If that's the case I might as well just start a timer in sync with the clock change, but it would be off by about 15 microsecond.....

Share this post


Link to post
Share on other sites

OS multitasking will introduce random drops in your time scale. I don't mean crystal drift here, but that you just don't own every time slice.

Depending on your context / needs / budget you might as well nail it by buying an add-on board with ad-hoc hardware to perform what you want, which is ???


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

OS multitasking will introduce random drops in your time scale. I don't mean crystal drift here, but that you just don't own every time slice.

Depending on your context / needs / budget you might as well nail it by buying an add-on board with ad-hoc hardware to perform what you want, which is ???

I don't understand how it affects my function. The timer functions count the total time elapsed since they started, regardless of what the system is doing. There's a known variance of up to 15 microseconds, due to the time required to get the data from the timer.

The purpose is not to process every of the set, but to be able to retrieve the system time to a certain degree of accuracy. (within 15microseconds is acceptable for most needs)

Share this post


Link to post
Share on other sites

What I'm trying to say is that if you need to precisely timestamp real-world event (external to the machine) you will not acheive the accuracy that the machine-level timer is capable of, because events may (and will) occur within time slices where your program is idle.

That it could be a deal-breaker or not in your context is up to you to decide, especially since we still don't have the faintest idea of your requirements.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

What I'm trying to say is that if you need to precisely timestamp real-world event (external to the machine) you will not acheive the accuracy that the machine-level timer is capable of, because events may (and will) occur within time slices where your program is idle.

That it could be a deal-breaker or not in your context is up to you to decide, especially since we still don't have the faintest idea of your requirements.

No all events are internal, and all data is relative. I simply needed to get how many microseconds had elapsed since the last millisecond. And a variance of up to 30microseconds is acceptable (0.003%)

Share this post


Link to post
Share on other sites

_TimerInit / _TimerDiff currently give the same results as built-in TimerInit / TimerDiff and these values are based on the 14.31818 MHz TV oscillator inherited from the first PC (before PC-XT), hence a ≈ 69.84128 ns resolution at the hardware level at the very best.

Physical drift, temperature, issues in implementation, overhead in abstraction layer(s) and numerous other untold infuencial factors will surely decrease practical accuracy seen in applicative software but certainly not up to 30 µs.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

_TimerInit / _TimerDiff currently give the same results as built-in TimerInit / TimerDiff and these values are based on the 14.31818 MHz TV oscillator inherited from the first PC (before PC-XT), hence a ≈ 69.84128 ns resolution at the hardware level at the very best.

Physical drift, temperature, issues in implementation, overhead in abstraction layer(s) and numerous other untold infuencial factors will surely decrease practical accuracy seen in applicative software but certainly not up to 30 µs.

So your saying the measurement for picoseconds and femto seconds are not accurate, though returned by the counter? (are you saying every measurement will be off by about 69 ns?)

Share this post


Link to post
Share on other sites

I don't even measure down to 10 fs (femtosecond) with costly high-end lab equipment!

A lot (whole lot) of things happen in today's PCs. Whatever is read/writen in I/O goes thru the HAL (hardware abstraction layer) then to device driver then to system layers then to application. In the meantime countless tasks of various priority and privilege may delay percolation of raw data: today's OSes are really complex, DOS is really ligthyears behind.

I'm not making up this, even MSDN writes it. At any rate (pun intended) even few cycles of circa 70 ns lost from time to time aren't going to change anything for you. Also consider that the accuracy and stability of the performance counters (based on this prehistoric 14.31818 TV Xtal) are not considered critical for a general-purpose machine. Typical drift of such a low-end oscillator (now implemented by a frequency generator) can be ±2 s/day and still be considered as good enough. That is ± 23 µs per second. Note that this frequency source is distinct from the RTC (real-time clock).


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Measuring down to to pico and femto seconds might be a bit overkill...

The precision with which I am measuring time determines the the total probable outcomes of my algorithm, thus picosecond precision would allow for one trillion possible outcomes per second.

I'm synchronizing the timer at a ms level every 5 seconds, so the returned data is fairly accurate relative to the system time.

Edited by nullschritt

Share this post


Link to post
Share on other sites

I wish you the best of luck.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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  
Followers 0