Of course, there's always gethrtime() which returns the time in µs.
/ David Hedbor
Previous text:
2003-09-18 22:59: Subject: time() and optimization again
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
time() was implemented this way *because* of the limited float precision. Basically, you are supposed to do this:
int base_time=time(); float offset=time(base_time); // seconds since 'base_time'
Generally, I put the first line globally in my program.
If you want a better time function, you could implement it like this:
int mstime() // Time in milliseconds { int t=time(); float off=time(t); return (off * 1000) + (t * 1000); }
/Hubbe
/ Fredrik (Naranek) Hubinette (Real Build Master)