From cbf7ecee926ee8efc489f614005a813db0f56bb7 Mon Sep 17 00:00:00 2001 From: "balhau@balhau.net" Date: Sat, 25 Dec 2021 17:08:21 +0000 Subject: [PATCH] Added timer.hpp --- src/platform/timer.hpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/platform/timer.hpp diff --git a/src/platform/timer.hpp b/src/platform/timer.hpp new file mode 100644 index 0000000..fd93431 --- /dev/null +++ b/src/platform/timer.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include +#include + +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; + } + }; +}; \ No newline at end of file