Try System.Time() (or, if you want relative times, System.Timer())
/ Per Hedbor ()
Previous text:
2003-09-14 18:19: Subject: time() and optimization again
Hi,
Long time ago I posted a message about wrong optimization with time() (and perhaps something else). Nobody replied, and the problem is still present in recent CVS (7.4.27). So here it is again:
--- snip --- Just found another bug(?) - the construction like:
int ts = time() + 10; while (time() < ts) /* nothing */ ;
is wrongly optimized - it doesn't work as expected, i.e. the loop is bypassed - so virtually there is no delay.
When I change it to 'while ((n = time()) < ts);' or put something in body, it works.
Checked against one day old CVS Pike 7.4 (7.4.17).
NB: Is it related to time() only or? :) --- snip ---
Also, there is a (slight) inconvenience with time() function. To retrieve current time with high precision I've to use time(2)+2.0, since only this syntax allow to retrieve time with microsecond precision. But, unfortunately, it adds 2 seconds to the result. Sure, extra float op is nothing (almost), but at least inconvenient and misleading.
Would it be a good idea to add an extra option (say, negative argument) to return current time as float without using base (which is the case when argument is > 1)?
And last about time() :) When Pike is compiled with default float size, its float result is absolutely unrealiable (even wrong) - because of very limited precision (just try: time() - (int)(time(2)+2), the difference will impress you).
Yes, I know that there is gethrtime() etc., but I can't use it (directly) with call_out(), for instance (and gethrtime() involves MPI, which is quite slow comparing to floats, even double precision floats).
Regards, /Al
/ Brevbäraren