19#ifndef _GIMLI_STOPWATCH__H
20#define _GIMLI_STOPWATCH__H
28static __inline__
size_t rdtsc__(
void){
30 __asm__
volatile (
".byte 0x0f, 0x31" :
"=A" (
x));
33#elif defined(__x86_64__)
34static __inline__
size_t rdtsc__(
void){
36 __asm__ __volatile__ (
"rdtsc" :
"=a"(lo),
"=d"(hi));
37 return ((
size_t)lo)|(((size_t)hi)<<32);
40static inline size_t rdtsc__(
void){
47class DLLEXPORT CycleCounter{
49 CycleCounter() : var_(0) {}
53 inline void tic(){ var_ = rdtsc__(); }
55 inline size_t toc()
const {
return (rdtsc__() - var_); }
62class DLLEXPORT Stopwatch {
64 Stopwatch(
bool start=
true);
70 void stop(
bool verbose=
false);
84 const CycleCounter & cycleCounter()
const {
return _cCounter; }
90 const RVector &
stored()
const {
return *this->_store;}
94 enum watchstate {undefined,halted,running} _state;
96 std::chrono::time_point<std::chrono::high_resolution_clock> _start, _stop;
99 CycleCounter _cCounter;
102#define TIC__ std::cout.precision(12); GIMLI::Stopwatch __swatch__(true);
103#define TOC__ std::cout << __swatch__.duration(true) << std::endl;
104#define toc__ __swatch__.duration()
Definition stopwatch.h:47
void store(bool restart=false)
Definition stopwatch.cpp:83
void restart()
Definition stopwatch.cpp:50
size_t cycles(bool restart=false)
Definition stopwatch.cpp:87
void reset()
Definition stopwatch.cpp:55
double duration(bool restart=false)
Definition stopwatch.cpp:60
const RVector & stored() const
Definition stopwatch.h:90
GIMLi main namespace for the Geophyiscal Inversion and Modelling Library.
Definition baseentity.h:24
RVector x(const R3Vector &rv)
Definition pos.cpp:107