Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include <ctime>
- #include <chrono>
- #include <cmath>
- class Timer {
- private:
- std::chrono::time_point<std::chrono::system_clock> m_StartTime;
- std::chrono::time_point<std::chrono::system_clock> m_EndTime;
- bool m_bRunning = false;
- public:
- void start() {
- this->m_StartTime = std::chrono::system_clock::now();
- this->m_bRunning = true;
- }
- void end() {
- this->m_EndTime = std::chrono::system_clock::now();
- this->m_bRunning = false;
- }
- double elapsedMilliseconds() {
- std::chrono::time_point<std::chrono::system_clock> endTime;
- if (this->m_bRunning) {
- endTime = std::chrono::system_clock::now();
- }
- else {
- endTime = this->m_EndTime;
- }
- return std::chrono::duration_cast<std::chrono::milliseconds>(endTime - m_StartTime).count();
- }
- double elapsedSeconds() {
- return this->elapsedMilliseconds() / 1000.0;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement