1
Fork 0
mirror of https://github.com/Jaxan/hybrid-ads.git synced 2025-04-27 23:17:44 +02:00
hybrid-ads/lib/logging.hpp

42 lines
739 B
C++

#pragma once
#include <chrono>
#include <iostream>
struct timer{
using clock = std::chrono::high_resolution_clock;
using time = std::chrono::time_point<clock>;
using seconds = std::chrono::duration<double>;
std::string name;
time begin;
bool active = true;
timer(std::string name)
: name(name)
, begin(clock::now())
{
std::cerr << name << std::endl;
}
void stop(){
if(!active) return;
time end = clock::now();
std::cerr << "* " << from_duration(end - begin) << '\t' << name << std::endl;
active = false;
}
~timer(){
stop();
}
static double from_duration(seconds s){
return s.count();
}
};
// has same signature, but does not log :)
struct silent_timer {
silent_timer(std::string){}
void stop();
};