// Main.cpp
#include <iostream>
#include "Timer.h"
int main() {
Timer::begin("Test");
Timer::stop();
std::cin.get();
}
// Timer.h
#pragma once
#include <string>
#include <chrono>
class Timer {
private:
static std::string label;
static std::chrono::steady_clock::time_point start;
static std::chrono::steady_clock::time_point end;
public:
static void begin(std::string);
static void stop();
};
// Timer.cpp
#include <iostream>
#include <string>
#include <chrono>
#include "Timer.h"
void Timer::begin(std::string timer_name) {
label = timer_name;
start = std::chrono::high_resolution_clock::now();
}
void Timer::stop() {
auto end = std::chrono::high_resolution_clock::now();
auto duration = end - start;
std::cout << label << ':' << " took " << duration.count() << "ns" << std::endl;
}