timer: add a stopwatch for timing a simple operation

* src/misc/timer.hh (stopwatch): New class, implemented on top
of C++11's std::chrono::high_resolution_clock.
* src/bin/dstar2tgba.cc, src/bin/ltl2tgba.cc, src/bin/ltlcross.cc:
Use it in lieu of gethrxtime(), so we do not need to distribute
gethrxtime anymore.
This commit is contained in:
Alexandre Duret-Lutz 2014-10-26 13:44:47 +01:00
parent 8d947a8782
commit a4f951facc
4 changed files with 41 additions and 17 deletions

View file

@ -31,7 +31,6 @@
#include <unistd.h>
#include <sys/wait.h>
#include "error.h"
#include "gethrxtime.h"
#include "argmatch.h"
#include "common_setup.hh"
@ -61,6 +60,7 @@
#include "misc/hash.hh"
#include "misc/random.hh"
#include "misc/tmpfile.hh"
#include "misc/timer.hh"
// Disable handling of timeout on systems that miss kill() or alarm().
// For instance MinGW.
@ -892,9 +892,10 @@ namespace
std::string cmd = command.str();
std::cerr << "Running [" << l << translator_num << "]: "
<< cmd << std::endl;
xtime_t before = gethrxtime();
spot::stopwatch sw;
sw.start();
int es = exec_with_timeout(cmd.c_str());
xtime_t after = gethrxtime();
double duration = sw.stop();
const char* status_str = 0;
@ -1043,8 +1044,7 @@ namespace
statistics* st = &(*fstats)[translator_num];
st->status_str = status_str;
st->status_code = es;
double prec = XTIME_PRECISION;
st->time = (after - before) / prec;
st->time = duration;
// Compute statistics.
if (res)