ScopeTimer + small fixes
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "timeutil.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using std::chrono::high_resolution_clock;
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::microseconds;
|
||||
@@ -11,6 +13,12 @@ int64_t timeutil::Timer::stop() {
|
||||
return duration_cast<microseconds>(high_resolution_clock::now()-start).count();
|
||||
}
|
||||
|
||||
timeutil::ScopeLogTimer::ScopeLogTimer(long long id) : scopeid_(id) {}
|
||||
|
||||
timeutil::ScopeLogTimer::~ScopeLogTimer() {
|
||||
std::cout << "Scope "<< scopeid_ <<" finished in "<< ScopeLogTimer::stop() << " micros."<<std::endl;
|
||||
}
|
||||
|
||||
float timeutil::time_value(float hour, float minute, float second) {
|
||||
return (hour + (minute + second / 60.0f) / 60.0f) / 24.0f;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,19 @@ namespace timeutil {
|
||||
int64_t stop();
|
||||
};
|
||||
|
||||
/* Timer that stops and prints time when destructor called
|
||||
* @example:
|
||||
* { // some scope (custom, function, if/else, cycle etc.)
|
||||
* timeutil::ScopeLogTimer scopeclock();
|
||||
* ...
|
||||
* } */
|
||||
class ScopeLogTimer : public Timer{
|
||||
long long scopeid_;
|
||||
public:
|
||||
ScopeLogTimer(long long id);
|
||||
~ScopeLogTimer();
|
||||
};
|
||||
|
||||
float time_value(float hour, float minute, float second);
|
||||
void from_value(float value, int& hour, int& minute, int& second);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user