Opened 14 years ago

Closed 13 years ago

#1962 closed Bugs (wontfix)

Doesn't measure wall clock time

Reported by: Dave Abrahams Owned by: Beman Dawes
Milestone: Boost 1.36.0 Component: timer
Version: Boost 1.35.0 Severity: Problem
Keywords: Cc:

Description

The attached program, when run on my tickless (kernel 2.6.24) dual-core linux system, demonstrates that boost::timer isn't measuring what we want it to.

Attachments (1)

thread4.cpp (2.7 KB ) - added by Dave Abrahams 14 years ago.

Download all attachments as: .zip

Change History (3)

by Dave Abrahams, 14 years ago

Attachment: thread4.cpp added

comment:1 by r.jordans@…, 14 years ago

The problem here is a generic one. The timer class uses clock() to measure time and this function is defined differently for Windows and Unix systems. On Windows it is defined as the wall clock time while on most Unix derivatives the total CPU time of the process is used.

A simple example: (test_clock.c) #include <time.h> #include <stdio.h> #include <unistd.h>

int main(int argc, char argv) {

time_t start = clock();

printf("Sleeping 1 second... "); fflush(stdout);

sleep(1);

printf("done\n"); printf("Time elapsed: %f\n", (clock()-start)/((float)CLOCKS_PER_SEC) );

return 0;

}

Will result in the following output: roel@localhost:~ $ ./test_clock Sleeping 1 second... done Time elapsed: 0.000000

Which is a completely different concept of time when compared to the result on Windows.

comment:2 by Beman Dawes, 13 years ago

Resolution: wontfix
Status: newclosed

<timer.hpp> measures whatever time std::clock measures. Unfortunately, this varies from system to system.

The fix is to retire <timer.hpp>, and replace it with a much better set of facilities based on C++0x <chrono>.

I've been working on these facilities in svn.boost.org/svn/boost/sandbox/chrono

Currently, the header is <boost/chrono/timer.hpp>. It supplies:

  • process_clock: capturing real, user-CPU, and system-CPU clocks.
  • process_timer: capturing elapsed real, user-CPU, and system-CPU times.
  • run_timer: convenient reporting of process_timer results.

I'm probably going to move these to a new Boost.Timer library.

--Beman

Note: See TracTickets for help on using tickets.