This message was edited by Phat Nat at 2005-5-2 20:45:6
: hi everybody,
:
: i want to create a timer so that i could time my program to calculate it's time efficiency. So how would i create it in pascal.
:
You can also get a running clock (18.2 times/second) from memory. I'm not sure if it changes location, but you can just do a display of your lower memory ($0000:$0000 -> $0100:0000) to your screen and find the part that's counting. On my machine it's at Mem[$0046:$000C]; It's really quick returning the memory, so there is no "added" time to your testing due to interrupt calls, etc.
USES Crt, Dos;
VAR
X : Word;
L : LongInt;
Begin
Repeat
GotoXY(1,1);
Move(Mem[$0046:$000C],L,4);
WriteLn(L);
{ This displays the lower memory }
{ For X := 0 to 2500 Do
Mem[$B800:X*2] := Mem[$0000:$0000+X];
}
Until Keypressed;
End.
If you just save the memory location to a variable such as
L above, you can save it again to another variable and suctract. The second will always be larger (except in the very rare occasion that the clock actually fills the whole LongInt) so when you subtract the 2 numbers you can get the # of seconds it took by dividing by 18.2
USES Crt, Dos;
VAR
TStart : LongInt;
TEnd : LongInt;
Begin
ClrScr;
Move(Mem[$0046:$000C],TStart,4);
Repeat
GotoXY(1,1); WriteLn('Random # = ',Random(240));
Until Keypressed;
Move(Mem[$0046:$000C],TEnd,4);
WriteLn('It looped for ',TEnd-TStart,' clock ticks.');
WriteLn('It looped for ',(TEnd-TStart)/18.2:1:1,' seconds.');
End.
Used this many times. Comes in very handy ;)
Phat Nat