On Fri, 27 Feb 2004, Toby Ewing wrote:
Hi, all
There have been some recent improvements to the Mersenne Twister (the random number generator that is used in the GPC unit), and I've been translating them into Pascal for eventual submission to the programming team. As part of this, I wanted to check the execution time, so I wrote a timer (I thought!) into a test program:
program testMT; uses GPC, MTrand; {MTrand is the name of the unit I'm working on} const big = 10000000; TimeFormat = ' %Q'; var t1, t2, i, j : medCard; CurrentTime : TimeStamp;
begin SeedRand(1234567890); GetTimeStamp (CurrentTime); WriteStr(FormatTime(CurrentTime, TimeFormat), t1); { line 17 } for i := 1 to big do j := randInt; GetTimeStamp (CurrentTime); WriteStr(FormatTime(CurrentTime, TimeFormat), t2); Writeln('Elapsed time: ', (t2 - t1):1); end.
First, use writeln instead of writestr.
Second, if you use only the 'Q' part of unixtime you might start near the end of a second and get a roll over, thus giving you a negative number for elapsed time
Try this:
program timeMT; uses GPC; const big = 10000000; var i, j : medCard; CurrentTime, CurrentTime2 : longint;
begin Currenttime := GetMicrosecondTime; writeln( Currenttime ); {you really don't need this line}
for i := 1 to big do j := 2*2*2; {dummy line to get some elapsed time}
Currenttime2 := GetMicrosecondtime; writeln( Currenttime2 ); {you don't need this line, either} Writeln('Elapsed time: ', (Currenttime2 - Currenttime)); end.
Russ