Boost logo

Boost :

Subject: [boost] [chrono][stopwatches] Request for interest in NEW stopwatch/timer reporting facilities
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2011-09-13 18:11:45


Hi,

I has been reconsidering the reporting facilities of proposed
Boost.Stopwatches. I have started to make some examples that make use
Boost.Format to make the reports.

Default reporting
   stopclock<> sw;

prints the duration

29308.350 µs

You can make a boost::format and pass it to the stopclock.

void f1(long j)
{
   boost::format fmt("%1%[%2%] f1(%3%) - Elapsed time: %4%");
   fmt % __FILE__ % __LINE__ % j;
   stopclock< > sw(fmt);
   // burn some time
}

../example/scoped_stopwatch_example.cpp[42] f1(1000000) - Elapsed time:
29834.769 µs
../example/scoped_stopwatch_example.cpp[51] void f2(long int) - Elapsed
time: 0.979 µs

You can change the precision, the output stream, the units and the unit
text using a specific formatter. For example

   typedef elapsed_formatter<milli > formatter;
   formatter fmt("Elapsed time: %1%", std::cerr);
   fmt.set_duration_style(text);
   fmt.set_precision(6);

   stopclock<high_resolution_clock, formatter> sw(fmt);

could print

Elapsed time: 87.829801 milliseconds

This formatter could be shared between several stopclocks (thread unsafe
however).

Even if the reporting facilities will not be completly 'localizable', I
think that this interface goes one step towards in this direction.

Before continuing the adaptation of the whole library I would like to
hear some comments from you. Do you think this is an acceptable interface?
What are the parameters that do you want to manage? procession, unit,
short/long units, ...

Best,
Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk