Added timer.hpp

This commit is contained in:
balhau@balhau.net 2021-12-25 17:08:21 +00:00
parent 306f84115c
commit cbf7ecee92
No known key found for this signature in database
GPG key ID: 1E666F326A121830

37
src/platform/timer.hpp Normal file
View file

@ -0,0 +1,37 @@
#pragma once
#include <iostream>
#include <sys/time.h>
namespace platform
{
class Timer
{
private:
std::string label;
long int start;
long int end;
long int gettime()
{
struct timeval tp;
gettimeofday(&tp, NULL);
long int ms = tp.tv_sec * 1000 + tp.tv_usec / 1000;
return ms;
};
public:
Timer(const char* lbl) : label(lbl)
{
this->label=std::string(lbl);
this->start = gettime();
}
~Timer()
{
this->end=this->gettime();
unsigned long diff = this->end - this->start;
std::cout << this->label << diff << std::endl;
}
};
};