refactor: return numerical value from timer
This commit is contained in:
parent
f7634bdd95
commit
64ae4c62a9
3 changed files with 17 additions and 16 deletions
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue