On Fri, Jul 25, 2008 at 5:29 PM, Bruno Lalande <
bruno.lalande@gmail.com> wrote:
> What platform is that?
A very common one: Linux 2.6 with GCC 4.1 or 4.2. The distribution is Kubuntu.
timer().elapsed_max() gives 2147.48 on this platform and indeed,
elapsed() returns negative numbers above that time (before returning
to 0).
I had thought about the possibility of making a policy-based version
of boost::timer, with something like a "heart policy" that would
define the way in which the time would be obtained and stored
internally. There would be a portable one (the one of boost::timer
currently), another one based on boost::date_time, and why not some
platform-specific ones (QueryPerformanceCounter on windows for
instance). But I never had the time to dig more :-(
I don't mean to hijack the thread but please let me share another way to use timer,
with C, not C++ or boots. In the code, not only the time of one test, but average time,
and its standard derivation are calculated so we will know how "close" is the average time.
My question: Is there any similar implementation in boost?
The code is as follows:
int count = 30;
long long times[count];
for (i = 0; i < count; i++) {
time start;
gettimeofday (&start, NULL);
// do something
gettimeofday (&end, NULL);
long long time = ((end.tv_sec - start.tv_sec) * 1000000 +
(end.tv_usec - start.tv_usec));
times[i] = time;
}
// and use it
printf("mean: %f, stddev: %f\n", mean(times, 20), stddev(times, 20);
double
variance (long long *x, int n)
{ double m = x[0];
double s = 0;
int i;
for (i = 0; i < n; i++)
{
double m_new = m + (x[i] - m) / (i + 1);
s = s + (x[i] - m) * (x[i] - m_new);
m = m_new;
}
return s / (n - 1);
}
double
mean (long long *x, int n)
{ double m = x[0];
int i;
for (i = 0; i < n; i++)
{
m = m + (x[i] - m) / (i + 1);
}
return m;
}
double
stddev (long long *x, int n)
{
return sqrt (variance (x, n));
}