I needed this functionality for some high precision calculations I'm making. (autoit is not fast enough to support counting nanoseconds, sorry!)
What's it do?
It returns the number of microseconds past the current millisecond on the system clock.
How accurate is it?
Due to autoit limitations the counter will always be between 3-15 microseconds behind the system.
->*(This is how long autoit takes to initialize a counter)
Example + UDF:
_microsecinit() ;we HAVE to call this first to initialize the the counter
while 1
sleep(random(25,100)) ;random sleep to show microsecond difference better
ConsoleWrite(@yday&'/'&@year&' '&@HOUR&':'&@MIN&':'&@SEC&':'&@MSEC&':'&_microseconds()&@CRLF) ;call _microseconds() to get the microseconds
WEnd
Func _microseconds()
local $ms, $ms2
if TimerDiff($microtimer) > 5000 Then
$ms = @MSEC
$ms2 = $ms
Do
$ms2 = @MSEC
Until $ms2 > $ms
$microtimer = TimerInit() ;attempt to re-sync microseconds
EndIf
$time = StringSplit(TimerDiff($microtimer), ".")
$time = StringLeft($time[2], 4)
return $time
EndFunc
func _microsecinit()
local $ms, $ms2
$ms = @MSEC
$ms2 = $ms
Do
$ms2 = @MSEC
Until $ms2 > $ms
global $microtimer = TimerInit()
EndFunc
If you have any ways of making it more precise, please submit it!