Created
June 5, 2018 21:19
-
-
Save luluco250/92dd79522447f64eb51e740331b0d082 to your computer and use it in GitHub Desktop.
C++ Stopwatch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef STOPWATCH_HPP | |
#define STOPWATCH_HPP | |
#include <chrono> | |
namespace detail { | |
using namespace std::chrono; | |
using hrc = high_resolution_clock; | |
class Stopwatch { | |
protected: | |
hrc::time_point _start, _last_lap; | |
public: | |
void start() { | |
_start = hrc::now(); | |
_last_lap = _start; | |
} | |
float lap() { | |
auto d = duration<float>(hrc::now() - _last_lap); | |
_last_lap = hrc::now(); | |
return d.count(); | |
} | |
float reset() { | |
auto d = duration<float>(hrc::now() - _start); | |
start(); | |
return d.count(); | |
} | |
}; | |
} | |
using Stopwatch = detail::Stopwatch; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment