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