16static long long frequency;
17static bool queried_perfcounter =
false;
19constexpr auto S_TO_NS=1000000000LL;
20constexpr auto NS_TO_S=(1.0/double(S_TO_NS));
26 if (!queried_perfcounter) {
27 QueryPerformanceFrequency((LARGE_INTEGER*) &frequency);
28 queried_perfcounter =
true;
30 QueryPerformanceCounter((LARGE_INTEGER*) &start);
33 clock_gettime(CLOCK_MONOTONIC, &ts);
34 start = ((
long long)ts.tv_sec)*S_TO_NS + (
long long)ts.tv_nsec;
39stopwatch::stopwatch(
bool silent) : silent(silent)
46stopwatch::stopwatch(
double *result,
bool silent) : silent(silent)
48 this->resultd = result;
52double stopwatch::get_current_time(
long long& end)
const
56 QueryPerformanceCounter((LARGE_INTEGER*) &end);
57 time =(end-start)/(
double)frequency;
60 clock_gettime(CLOCK_MONOTONIC, &ts);
61 end = ((
long long)ts.tv_sec)*S_TO_NS + (
long long)ts.tv_nsec;
62 time = double(end - start)*NS_TO_S;
71 return get_current_time(end);
78 double time = get_current_time(end);
84void stopwatch::add_time()
86 double time = restart();
91 std::cout <<
"elapsed time in seconds: " <<
time << std::endl;
95stopwatch::~stopwatch()
double get_elapsed_time() const
return time elpased thus far
double restart()
restart timer and return time elapsed until restart
namespace that holds tools that dont fit any other namespace
this header is dependency free