Added timer.hpp
This commit is contained in:
parent
306f84115c
commit
cbf7ecee92
1 changed files with 37 additions and 0 deletions
37
src/platform/timer.hpp
Normal file
37
src/platform/timer.hpp
Normal 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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in a new issue