Recent

Author Topic: get time since program runs  (Read 10382 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: get time since program runs
« Reply #15 on: July 05, 2017, 07:12:05 pm »
I would keep everything simply as TDateTime... That is a double, not a record.
Specialize a type, not a var.

Eugene Loza

  • Hero Member
  • *****
  • Posts: 663
    • My games in Pascal
Re: get time since program runs
« Reply #16 on: July 05, 2017, 09:53:25 pm »
emm... WHY make it SOOO hard? it's just
Code: Pascal  [Select][+][-]
  1. Program MyProg;
  2. var StartTime: Double;
  3. Begin
  4.   StartTime := now;
  5.   //do something;
  6.   WriteLn(MilliSecondsBetween(Now, StartTime));
  7. End.

Rewriting the original code:
Code: Pascal  [Select][+][-]
  1. Program MyProg;
  2. var cooldown: double;
  3. Begin
  4.   cooldown := now + 100/24/60/60/1000;
  5.   while true do begin
  6.     if Now > cooldown then begin
  7.        writeln(now); //something more user-friendly might be shown here, but I'm too lazy to check the syntax.
  8.        cooldown := now + 100/24/60/60/1000;
  9.     end;
  10.   end;
  11. End.
P.S. Pay attention, your C code will never show anything as it will constantly shift cooldown by 100 ms every "while" round. I've moved cooldown initialization outside the while loop.
P.P.S. You might also want to note that now (and clock() too) have discretization of approx. 7 msec, if I remember it correctly. So you'll always get more than 100 ms interval between displayed times. Additional effort should be made to make the intervals as close to 100 ms as possible.
« Last Edit: July 05, 2017, 10:03:52 pm by Eugene Loza »
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

Flaze07

  • New Member
  • *
  • Posts: 36
Re: get time since program runs
« Reply #17 on: July 06, 2017, 09:10:55 am »
nah, it will show something around 100-110
pascal is good for learning programming language

Flaze07

  • New Member
  • *
  • Posts: 36
Re: get time since program runs
« Reply #18 on: July 06, 2017, 09:12:01 am »
I would keep everything simply as TDateTime... That is a double, not a record.
didn't know that
pascal is good for learning programming language

Flaze07

  • New Member
  • *
  • Posts: 36
Re: get time since program runs
« Reply #19 on: July 06, 2017, 09:13:34 am »
P.P.S. You might also want to note that now (and clock() too) have discretization of approx. 7 msec, if I remember it correctly. So you'll always get more than 100 ms interval between displayed times. Additional effort should be made to make the intervals as close to 100 ms as possible.

thank you, I didn't know that...guess ctime isn't that reliable
pascal is good for learning programming language

Kays

  • Hero Member
  • *****
  • Posts: 569
  • Whasup!?
    • KaiBurghardt.de
Re: get time since program runs
« Reply #20 on: September 17, 2017, 04:56:51 pm »
[post's title reads: “get time since program runs”]
So your main goal's to obtain the duration since the program's been invoked. Hm, sure you can run a timer on your own, but I'd rather query the OS directly, e.g. by reading /proc/self/stat (Linux with procfs(5) mounted) or querying the kernel kinfo_getproc(3) (FreeBSD). Depending on your scenario either approach's more promising.

Eugene's method is quite neat, though.
[…]
Code: Pascal  [Select][+][-]
  1. []
  2.   StartTime := now;
  3.   //do something;
  4.   WriteLn(MilliSecondsBetween(Now, StartTime));
  5. []
[…]
Yours Sincerely
Kai Burghardt

Flaze07

  • New Member
  • *
  • Posts: 36
Re: get time since program runs
« Reply #21 on: September 24, 2017, 09:43:27 am »
wasn't expecting reply when I revisited
pascal is good for learning programming language

 

TinyPortal © 2005-2018