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:
parent
8d947a8782
commit
a4f951facc
4 changed files with 41 additions and 17 deletions
|
|
@ -29,6 +29,7 @@
|
|||
# include <iosfwd>
|
||||
# include <string>
|
||||
# include <map>
|
||||
# include <chrono>
|
||||
# if SPOT_HAVE_SYS_TIMES_H
|
||||
# include <sys/times.h>
|
||||
# endif
|
||||
|
|
@ -40,6 +41,33 @@ namespace spot
|
|||
/// \addtogroup misc_tools
|
||||
/// @{
|
||||
|
||||
|
||||
/// \brief A simple stopwatch
|
||||
struct stopwatch
|
||||
{
|
||||
protected:
|
||||
typedef std::chrono::high_resolution_clock clock;
|
||||
clock::time_point start_;
|
||||
public:
|
||||
/// Marks the start if the measurement
|
||||
void start()
|
||||
{
|
||||
start_ = clock::now();
|
||||
}
|
||||
|
||||
/// \brief Returns the elapsed duration in seconds.
|
||||
///
|
||||
/// May be called multiple times, and will always return the
|
||||
/// duration since the last call to start().
|
||||
double stop()
|
||||
{
|
||||
auto t = clock::now();
|
||||
typedef std::chrono::duration<double> seconds;
|
||||
return std::chrono::duration_cast<seconds>(t - start_).count();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/// A structure to record elapsed time in clock ticks.
|
||||
struct time_info
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue