Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / getting the elapsed running time?

Author
Message
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 27th May 2010 22:29
I have this code which gets the time from call dll windows.kernel, "GetLocalTime", ptr , now how do I get it to show the amount of time its been running, it then builds a stirng to make hour mins and seconds and puts them like so 23:18:38.

Now how do I use what I have to make a timer that show days hours mins seconds like so 00:00:00:34, So that when I run it is starts at zero and counts up to show how long is been running.

I've tried inc time,1 but that goes to fast.

I was subtracting now time form last time to get a number of seconds but that did not seem to work right.

so anyone have any ideas?

Dark Physics makes any hot drink go cold.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 27th May 2010 22:32
Well, you could use timer(), and just store the timer value when the program starts...

global start_timer
start_timer=timer()

Then work out the number of seconds passed like this:

elapsed=(timer()-start_timer)/1000


Health, Ammo, and bacon and eggs!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th May 2010 22:33 Edited at: 27th May 2010 22:33
Why not just use TIMER?

If you take a copy of the timer when you start, then the amount of time you have been running in seconds is (TIMER()-StartTime)/1000.

[edit]Bah! You beat me by seconds

HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 27th May 2010 22:39 Edited at: 27th May 2010 23:05
cheers!

however the timer() does not match the time that windows.kernel is giving, meaning the seconds do not count together.

I'll have another go and see if it was something I was doing wrong before.

edit
seem to be working ok, wonder what I did wrong last time.

Dark Physics makes any hot drink go cold.
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 29th May 2010 19:30
Timer gives you seconds from midnight, so after the clock ticks over, the timer value will restart from 0.

My signature is NOT a moderator plaything! Stop changing it!
BMacZero
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 30th May 2010 05:41
I thought timer() was a count from when the system had been turned on?

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 30th May 2010 15:39
Nope, time in seconds since midnight I'm 90% certain.

(hmmm, just ran this code and it implies there's been 26 hours since midnight.. Maybe it is the system uptime?)



My signature is NOT a moderator plaything! Stop changing it!
BMacZero
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 30th May 2010 16:32
It's 6:30 AM here and I just turned on my computer, and your code gives me 8 minutes.

sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 30th May 2010 18:57
Timer() in dbpro is definitely system uptime because I ran into the problem before when it goes to negative values after so many days being continously on. Search forum ppl have asked about it before.
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 30th May 2010 19:03
Quote: "Nope, time in seconds since midnight I'm 90% certain."


It's milliseconds and I'm pretty sure it is time since the PC was turned on.
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 31st May 2010 01:43
I thought it was milliseconds since 1970

Rawwrr. Sig Fail.
Newcastle is awesome
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 31st May 2010 02:11
IanM's Hitimer() function starts at zero when u run u'r program.

sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 31st May 2010 12:04 Edited at: 31st May 2010 12:05
Quote: "IanM's Hitimer() function starts at zero when u run u'r program."


Interesting! Didn't know that and the docs do imply that it works the same as the built in dbpro timer. I think I'll use this instead from now on, saves storing the start time.
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 3rd Jun 2010 18:30
hooo, thanks for finding the hit timer, work a treat.

Dark Physics makes any hot drink go cold.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Jun 2010 00:28
Quote: "IanM's Hitimer() function starts at zero"

Recent change, simply to ensure that the chances of the timer overflowing are minimised as much as possible ... certainly for a period longer than any version of windows has ever or will ever run for

However, it selects zero time as the start time of the program, which isn't necessarily when you want to start timing from, hence Van's and my advice above.

Another method would be to use a timer from my plug-ins to increment a counter once per second - if you separately increment variables for seconds, hours, minutes and days then you can avoid the maths for calculating those separate values:


It's also a little more efficient too - the clock is only updated when it needs to be and you're not recalculating every frame either.

HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 4th Jun 2010 14:34
thanks for the demo code IanM.

When I working out how to use ticker I notice that this uses 1000th of a second, so how would I calculate what 300 second is, I've been trying 30000 but that leaves about 1100 ticks to go before it ends.

so I am trying to get ticker to start stop an d re-run when hitimer has run for five mins 300 seconds.

Dark Physics makes any hot drink go cold.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 4th Jun 2010 14:45
300 seconds would be 300x1000 ticks - or 300000, not 30000.

This would cause an exact 300 second delay:

sync on : sync rate 0
T=timer()
While timer()<(T+300000)
`Do stuff
text 0,0,str$((timer()-T)/1000)+"\300 seconds"
Endwhile


Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2026-07-25 16:20:14
Your offset time is: 2026-07-25 16:20:14