Raymond Wang wrote:
I see what the problem is: I'm using GNU Pascal as opposed to DEC VAX Pascal (where clock is a global function defined below).
Does anyone know a way to mimic this "clock" in GNU Pascal? (I apologize for my lack of Pascal knowledge!)
No problem (it's nothing to do with Pascal in general, anyway -- as Peter noted, the only predefined routines to deal with time in Pascal are GetTimeStamp etc., but they measure real time, not CPU time). As I said in my last mail, if you have a not too old GPC release, you can use GetCPUTime. (In contrast to VAX Pascal, the result is not "most likely" in 10ms intervals, but definitely in seconds and microseconds. :-) So, if you want a "most likely";-) VAX Pascal compatible `Clock' routine, you can use the following code. (I use `LongInt' for the return value just in case -- `Integer' would be good for 2^31/100/86400 ~ 249 days.) The demo program shows that really CPU time is measured, i.e., `Sleep' doesn't take up time, but the loop does. program Foo; uses GPC; { Compatible to VAX Pascal. Result is in 10ms intervals. } function Clock : LongInt; var Second, MicroSecond : Integer; begin Second := GetCPUTime (MicroSecond); Clock := 100 * LongInt (Second) + MicroSecond div 10000 end; var i : Integer; begin Writeln (Clock); Sleep (1); Writeln (Clock); for i := 1 to 100000000 do; Writeln (Clock); end. Frank -- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/ GPC To-Do list, latest features, fixed bugs: http://agnes.dida.physik.uni-essen.de/~gnu-pascal/todo.html
participants (1)
-
Frank Heckenbach