refactor: return numerical value from timer

This commit is contained in:
Michael Mandl 2024-03-20 09:58:40 +01:00
parent f7634bdd95
commit 64ae4c62a9
Signed by: mandlm
GPG key ID: 4AA25D647AA54CC7
3 changed files with 17 additions and 16 deletions

View file

@ -1,17 +1,14 @@
#include "timer.h"
#include <chrono>
#include <iostream>
Timer::Timer(std::string_view name) : name_(name) { start(); };
Timer::Timer() { start(); };
void Timer::start() { start_ = std::chrono::high_resolution_clock::now(); }
void Timer::stop() {
auto end = std::chrono::high_resolution_clock::now();
void Timer::stop() { end_ = std::chrono::high_resolution_clock::now(); }
auto duration =
std::chrono::duration_cast<std::chrono::microseconds>(end - start_);
std::cout << name_ << " took " << duration << std::endl;
long Timer::us() const {
return std::chrono::duration_cast<std::chrono::microseconds>(end_ - start_)
.count();
}