| View previous topic :: View next topic |
| Author |
Message |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Sun Apr 14, 2002 5:28 pm Post subject: Millisecs timing |
|
|
I want to time a process as accurately as possible. The smallest unit of time that @datetime
will return is seconds. But I'm sure that the output from @datetime() (no parameters) can be
interpreted to get millisecs. I just cannot figure out just how to do it.
Greetz
Dr. Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
Posted: Sun Apr 14, 2002 7:15 pm Post subject: |
|
|
The following should extract the values like you want
(it's from http://www.sools.nl/cgi-bin/Ultraboard/UltraBoard.pl?action=Read&BID=15&TID=3&P=1&SID=13):
| Code: |
option decimalsep,.
DIALOG CREATE,Datetime extractor,-1,0,289,170
DIALOG ADD,TEXT,tDatetime,8,8,,,Datetime:
DIALOG ADD,TEXT,tDatetime2,8,96
DIALOG ADD,TEXT,tDays,24,8,,,Days:
DIALOG ADD,TEXT,tDays2,24,96
DIALOG ADD,TEXT,tHours,40,8,,,Hours:
DIALOG ADD,TEXT,tHours2,40,96
DIALOG ADD,TEXT,tMinutes,56,8,,,Minutes:
DIALOG ADD,TEXT,tMinutes2,56,96
DIALOG ADD,TEXT,tSeconds,72,8,,,Seconds:
DIALOG ADD,TEXT,tSeconds2,72,96
DIALOG ADD,TEXT,tMilliseconds,88,8,,,Milliseconds:
DIALOG ADD,TEXT,tMilliseconds2,88,96
DIALOG ADD,TEXT,tMicroseconds,104,8,,,Microseconds:
DIALOG ADD,TEXT,tMicroseconds2,104,96
DIALOG ADD,TEXT,tNanoseconds,120,8,,,Nanoseconds:
DIALOG ADD,TEXT,tNanoseconds2,120,96
DIALOG ADD,TEXT,tRest,136,8,,,Rest:
DIALOG ADD,TEXT,tRest2,136,96
DIALOG SHOW
repeat
option fieldsep,.
%%dateTime = @datetime()
gosub parseDateTime
option fieldsep,|
parse "tDatetime2;tDays2;tHours2;tMinutes2;tSeconds2;tMilliseconds2;tMicroseconds2;tNanoseconds2;tRest2",%%dateTime|%%days|%%hours|%%minutes|%%seconds|%%milliseconds|%%microseconds|%%nanoseconds|%%rest
until @event()
exit
:parseDatetime
parse "%%days;%%rest",%%dateTime
%%hours = @fmul(0.%%rest,24)
parse "%%hours;%%rest",%%hours
%%minutes = @fmul(0.%%rest,60)
parse "%%minutes;%%rest",%%minutes
%%seconds = @fmul(0.%%rest,60)
parse "%%seconds;%%rest",%%seconds
%%milliseconds = @fmul(0.%%rest,1000)
parse "%%milliseconds;%%rest",%%milliseconds
%%microseconds = @fmul(0.%%rest,1000)
parse "%%microseconds;%%rest",%%microseconds
%%nanoseconds = @fmul(0.%%rest,1000)
parse "%%nanoseconds;%%rest",%%nanoseconds
exit
|
However this code isn't truely accurate in milliseconds, as I think
Windows maintains the date/time only accurately to approximately
50 milliseconds.
For true timing in milliseconds, the GetTickCount Windows API can
be used, showing the number of milliseconds elapsed since Windows
boot-up. VDS implements this API through @SYSINFO(WINBOOT),
however unfortunately they didn't make it accurate to milliseconds
This of course is a great idea for a new DLL.
Best regards,
Tommy
Last edited by Tommy on Wed Apr 24, 2002 12:20 am; edited 1 time in total |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Apr 14, 2002 7:29 pm Post subject: |
|
|
_______________________________________________________________________________________________________________________________________________________________________________________
Here's a simple script to check the difference
between @datetime() results in a one second
interval.
I agree with Tommy on the accuracy though,
on my system the figures are usually either
.12037 or .121528, even using the REALTIME
option. And it makes no difference if the script
is compiled or not.
| Code: |
OPTION PRIORITY, REALTIME
:START
%s = @datetime()
WAIT
%t = @datetime()
rem -- Check if whole numbers are same, so we can subtract
rem -- decimal parts only (otherwise we get a math error).
rem -- Also make sure both decimal parts are numeric.
if @not(@equal(@name(%s), @name(%t)) @numeric(@ext(%s)) @numeric(@ext(%t)))
goto START
else
%l = @len(@ext(%t))
%%diff = .@fsub(@ext(%t), @ext(%s))
%%diff = @format(%%diff, 1.%l)
INFO Decimal length = %l@cr()@cr()S = %s@cr()T = %t@cr()@cr()One second difference:@tab()@cr()%%diff
end
|
_________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Sun Apr 14, 2002 11:50 pm Post subject: |
|
|
Thanks, guys! That was great help - I got my timing going pretty good. If someone else should be
interested then here is my little timing routine built from Tommy's and Mac's ideas:
| Code: | option decimalsep,"."
option fieldsep,"."
%%dateTime1 = @datetime()
REM Do your stuff - here just a WAIT for passing time
wait 1.4
%%dateTime2 = @datetime()
%%elapsed = @fsub(%%dateTime2,%%dateTime1)
%l = @len(@ext(%%elapsed))
%%elapsed = @format(%%elapsed,1.%l)
gosub parseDateTime
info %%elapsed@CR()@CR()Time elapsed:@cr()hours=%%hours@cr()minutes=%%minutes@cr()seconds=%%seconds@cr()millisecs=%%milliseconds@cr()microsecs=%%microseconds
stop
:parseDatetime
parse "%%days;%%rest",%%elapsed
%%hours = @fmul(0.%%rest,24)
parse "%%hours;%%rest",%%hours
%%minutes = @fmul(0.%%rest,60)
parse "%%minutes;%%rest",%%minutes
%%seconds = @fmul(0.%%rest,60)
parse "%%seconds;%%rest",%%seconds
%%milliseconds = @fmul(0.%%rest,1000)
parse "%%milliseconds;%%rest",%%milliseconds
%%microseconds = @fmul(0.%%rest,1000)
parse "%%microseconds;%%rest",%%microseconds
exit |
Greetz
Dr. Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
Posted: Sun Apr 21, 2002 9:46 pm Post subject: |
|
|
Actually the MT DLL will do exactly what I was talking about:
| Code: |
option priority,realtime
external mt.dll
DIALOG CREATE,GetTickCount,-1,0,282,75
DIALOG ADD,STYLE,sTime,,12,BC,,
DIALOG ADD,TEXT,tInfo,8,8,,,Number of milliseconds elapsed since Windows boot up:
DIALOG ADD,TEXT,tTime,40,8,264,16,00000000,,sTime
DIALOG SHOW
repeat
dialog set,tTime,@mt(DateTime,TickCount)
until @event()
|
It should be pretty accurate
Still "only" accurate to 10 milliseconds though, it seems.
You can download mt.dll at:
http://www.vdsworld.com/index.php?page=download&file=mt.dll
Best regards,
Tommy
Last edited by Tommy on Wed Apr 24, 2002 12:21 am; edited 1 time in total |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Sun Apr 21, 2002 10:31 pm Post subject: |
|
|
Thanks, Tommy!
That's great - very easy to handle. Actually I already have the MT dll and use it in one of
my progs. I had just totally forgotten about that little tickcount feature
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|