|
Boost : |
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2007-04-30 16:12:20
Philippe Vaucher wrote:
> 3. Does anyone know if std::clock() isn't implemented on "linux" ? On
> the unbuntu and gentoo boxes I tried it keeps returning 0, while on windows
> it works.
>
It is implemented and works. I've got a 2.6.14 kernel 64-bit Gentoo with
a 2.5 glibc.
#include <ctime>
#include <cmath>
#include <iostream>
#include <ostream>
int main()
{
std::cout << "Start: " << std::clock() << std::endl;
for(int i = 0; i < 10000; ++i) {
double foo = std::sqrt(static_cast<double>(i));
std::cout << foo << "\b\b\b\b\b\b\b\b\b\b\b\b\b" << std::flush;
}
std::cout << "End: " << std::clock() << std::endl;
}
The program's output varies between 20000 and 90000. The first one is
always 0. clock() is supposed to measure elapsed CPU time, but the
initial value is unspecified. It's apparently always 0 in Linux.
The resolution doesn't seem to be very high, though. Given that
CLOCKS_PER_SEC is defined by POSIX to be 1000000 regardless of actual
resolution, and given that the values are always "rounded" to steps of
ten thousand, I'd guess the resolution is 100Hz. This is not as good as
the kernel timer resolution of 1000Hz that I have configured.
Sebastian Redl
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk