ElapsedMilliseconds() returns zero?
ElapsedMilliseconds() returns zero?
Am I doing something wrong?
debug ElapsedMilliseconds() returns zero
MyVal.q = ElapsedMilliseconds()
or whatever.
Old code I have is doing weird stuff due to this suddenly... should I install an old version of PB to see if it's a version thing or can someone see why I'm just lacking in sleep and doing something dumb...
This can't be right, I must be going mad
x86 and x64 the same
Thanks
debug ElapsedMilliseconds() returns zero
MyVal.q = ElapsedMilliseconds()
or whatever.
Old code I have is doing weird stuff due to this suddenly... should I install an old version of PB to see if it's a version thing or can someone see why I'm just lacking in sleep and doing something dumb...
This can't be right, I must be going mad
x86 and x64 the same
Thanks
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Re: ElapsedMilliseconds() returns zero?
The PureBasic Manual - ElapsedMilliseconds() wrote:Remarks
The absolute value returned is of no use since it varies depending on the operating system. Instead, this function should be used to calculate time differences between multiple ElapsedMilliseconds() calls.
Code: Select all
For i = 0 To 10
Debug ElapsedMilliseconds()
Delay(1000)
Next
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
- microdevweb
- Enthusiast
- Posts: 179
- Joined: Fri Jun 13, 2014 9:38 am
- Location: Belgique
Re: ElapsedMilliseconds() returns zero?
Hello,
That depend when you call this function
See this example :
That depend when you call this function
See this example :
Code: Select all
myval.q = ElapsedMilliseconds()
Debug myval ; it's normal because the program is started now
; i run a loop for some time
For i = 0 To 1000000
; i don't do anything
Next
myval = ElapsedMilliseconds()
Debug myval ; in my case print 85
Use Pb 5.73 lst and Windows 10
my mother-language isn't english, in advance excuse my mistakes.
my mother-language isn't english, in advance excuse my mistakes.
Re: ElapsedMilliseconds() returns zero?
In fact it's the description of the function in the help that is badly formulated (and it's worse in the french help « Renvoie le nombre de millisecondes qui se sont écoulées depuis le démarrage de l'ordinateur. » (Translation: Returns the number of milliseconds that have elapsed since the computer was started. ))
IMHO, the good description should be:
Returns the number of milliseconds that have elapsed since the function was first called in the program.
3000 OK
Edit: Kenmo is right, I seem to remember that the behaviour changed a few years ago but the help hasn't been updated.
IMHO, the good description should be:
Returns the number of milliseconds that have elapsed since the function was first called in the program.
Code: Select all
Debug ElapsedMilliseconds()
Delay(1000)
Debug ElapsedMilliseconds()
Delay(2000)
Debug ElapsedMilliseconds()
Edit: Kenmo is right, I seem to remember that the behaviour changed a few years ago but the help hasn't been updated.
Last edited by Marc56us on Fri Jan 24, 2020 2:59 pm, edited 2 times in total.
Re: ElapsedMilliseconds() returns zero?
You're not mad, the behavior changed a few years ago.
It used to return something like <time the system's been running> but now it's <time relative to the first call, t=0> so it's only useful for relative timing.
I think the reason for changing was: the original behavior was not reliable across systems, or not consistent across OSes (?) It's not described in the version history, but it might be discussed on this forum.
It used to return something like <time the system's been running> but now it's <time relative to the first call, t=0> so it's only useful for relative timing.
I think the reason for changing was: the original behavior was not reliable across systems, or not consistent across OSes (?) It's not described in the version history, but it might be discussed on this forum.
Re: ElapsedMilliseconds() returns zero?
It changed some time between 5.44 and 5.60, here's Fred's comment in 2017
viewtopic.php?f=13&t=67989#p503543
The English help was updated in 2019, but the French needs to be updated. Maybe others too
viewtopic.php?f=4&t=73191
viewtopic.php?f=13&t=67989#p503543
The English help was updated in 2019, but the French needs to be updated. Maybe others too
viewtopic.php?f=4&t=73191
Re: ElapsedMilliseconds() returns zero?
ahhhhh
okay. The actual value was never of much use except in comparing so I didn't notice that detail about the first call being set to 0
okay. The actual value was never of much use except in comparing so I didn't notice that detail about the first call being set to 0
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Re: ElapsedMilliseconds() returns zero?
Since a few versions PB uses QueryPerformanceCounter() instead of GetTickCount() for ElapsedMilliseconds() .
This has the following advantages:
This has the following advantages:
- GetTickCount() only returned results in steps of 32ms (or something similar). QueryPerformanceCounter() is much more accurate.
- The result of GetTickCount() is a long, which can lead to problems with server programs that run longer time, because a long is full after a few weeks. The result of QueryPerformanceCounter() is a quad, so it can run for several hundred thousand years.
sorry for my bad english
Re: ElapsedMilliseconds() returns zero?
Correct. GetTickCount() only returns valid times for approx 49 days. These days, PCs are left running a lot longer than that.
Re: ElapsedMilliseconds() returns zero?
I am a few late there. I discover this change only now...
Re: ElapsedMilliseconds() returns zero?
For long-term measurement, the date functions are also used. For runtime measurement, GetTickCount was also sufficient. The statement that it is a problem that this value is only a long and it leads to problems with an overflow is completely wrong and had already upset me at the time of the discussion.
The different calculation of the time is also always correct at the start before and at the end with an overflow of the long value. (Of course, only with a difference of less than about 47 days).
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive