[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: clock() function note ...
- From: Philippe Lhoste <PhiLho@...>
- Date: Mon, 10 Jun 2002 16:12:27 +0200 (MEST)
> The Lua clock() function measures the CPU time given to the process, so if
your program occupies 1% of the CPU on the average,
> clock() will measure 1/100 of the real elapsed time. If your process
occupies 100% of the CPU (almost impossible with
> multiprogramming operating systems) you would get the results you
> How to get the real time in Lua? I don't know...
> if you just want a precision around seconds, you can use date()
Unfortunately (AFAIK), on Windows, clock() just returns the time spent
between two calls. It doesn't return the CPU time given to the process, which
would have been useful indeed in multitask OS. I suppose such function would be
available only on WinNT, not on Win9x (and I don't even know how to access
If you take a look at the source of the CRT (C run-time), clock uses only
the GetSystemTimeAsFileTime API function. From MSDN: "The
GetSystemTimeAsFileTime function retrieves the current system date and time". Returns as a
FILETIME structure: "The FILETIME structure is a 64-bit value representing
the number of 100-nanosecond intervals since January 1, 1601 (UTC)".
The 100ns resolution is theoritical, I guess it is instead based on the old
Bios IRQ (18.2ticks/s if I recall correctly). I am not sure about the last
sentence, though :-)
This is why I implemented the performance counter routines, more precise,
although returning inconsistent results because of multitask. I usually make a
few runs and approximate a mean value.
If anybody here know how to make finer measures, let me know.
On the same (out of) topic, is there any way to reset the filesystem cache,
eg. to compare functions doing a recursive search in files? The second seach
is much faster than the first...
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
GMX - Die Kommunikationsplattform im Internet.