Hi,
I don't know which precision you need for time, but the following unit does all right for me; it can be modified for going down to millisecond resolution.
Silvio a Beccara
------------------------------------------------------------------------------------ unit times;
interface function times ( tend: boolean; var tinit: double ): double;
implementation uses SysUtils, types;
function times ( tend: boolean; var tinit: double ): double;
var seconds: double; TS : TTimeStamp; DT : TDateTime;
begin
if tend = false then begin TS:=DateTimeToTimeStamp(Now); tinit := TimeStampToMSecs ( TS ); end
else begin TS:=DateTimeToTimeStamp(Now); seconds := ( TimeStampToMSecs ( TS ) - tinit ) / 1000; result := seconds; end; end; end.
------------------------------------------------------------------------------------
| 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. | | The compiler hangs with the following error: | testmt.pas(17): Error: reference expected, value given | testmt.pas(17): Error: reference expected, value given | testmt.pas(17): Error: tree check: expected class 't', have 'x' | (error_mark) in require_complete_type, at p/typecheck.c:63 | Please submit a full bug report | | I'm guessing that it's not about my unit, but rather what I'm trying to do | with capturing a string into an int... anyway, here is a bug report. | | Toby