Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
how to create a timer to time a piece of code in pascal Posted by muaz_farooq on 2 May 2005 at 1:47 AM
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.
Report
Re: how to create a timer to time a piece of code in pascal Posted by zibadian on 2 May 2005 at 3:21 AM
: 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 use Now or GetTime, depending on your compiler. The general pseudo-code looks like this:
  Get current system clock
  Perform lengthy process
  Get current system clock
  Calculate run time.

Report
This post has been deleted. Posted by emily2010001 on 1 Jun 2010 at 6:17 AM
This post has been deleted.
Report
Re: how to create a timer to time a piece of code in pascal Posted by dolev9 on 2 May 2005 at 3:21 AM
its pritty simple.

check the gettime and settime procedures.
you need to use dos unit to use them.
these procedures exist in the tp help for more info.


gettime(var houre,minute,second,milisecond);
(gives you the current time)

settime(var houre,minute,second,milisecond);
(set time to (changes the clock))

getdate(var year,month,day,dayofweek);
(gives you the current date)

setdate(var year,month,day,dayofweek);
(set the current date)



to check how long takes program to do something do

gettime(hr1,mn1,sc1,ms1);
a := ms1+sc1*100+ms1*6000+hr1*360000;
...
...
...
gettime(hr2,mn2,sc2,ms2);
b := ms2+sc2*100+ms2*6000+hr2*360000;

c := a-b {milliseconds defferance}


when hour is 23:59:59:999
it wont work.
to make it work between days you should use also the getdate/setdate procedures.


hopefully i helped

dolev



Report
Re: how to create a timer to time a piece of code in pascal Posted by est69dog on 31 May 2010 at 8:33 AM
just add one "if"

gettime(h,m,s,ms);
if h>12 then h:=h-12;

make sure that you add it both times
it will if you dont use that program for 12h+
Report
Re: how to create a timer to time a piece of code in pascal Posted by Phat Nat on 2 May 2005 at 8:40 PM
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



Report
This post has been deleted. Posted by acetechcn on 31 May 2010 at 11:41 PM
This post has been deleted.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.