Created
July 12, 2014 14:43
-
-
Save ssendeavour/48879884963578d0eb0a to your computer and use it in GitHub Desktop.
Timing class using C++ 11 and chrono, used to measure time
This file contains hidden or 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
#include "Timing.h" | |
double Timing::getEllipsedMilliseconds() | |
{ | |
if (m_running) | |
{ | |
setToCurrentTime(m_endTime); | |
} | |
return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(m_endTime - m_startTime).count()) / 1000000.0; | |
} | |
void Timing::stopTiming() | |
{ | |
setToCurrentTime(m_endTime); | |
m_running = false; | |
} | |
void Timing::startTiming() | |
{ | |
setToCurrentTime(m_startTime); | |
m_running = true; | |
} | |
Timing::~Timing() | |
{ | |
} | |
Timing::Timing() | |
{ | |
startTiming(); | |
} | |
void Timing::setToCurrentTime(std::chrono::high_resolution_clock::time_point & timePoint) | |
{ | |
timePoint = std::chrono::high_resolution_clock::now(); | |
} |
This file contains hidden or 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
#pragma once | |
/************************************************************************ | |
* Function: Timing operation | |
* Date: 2014-07-13 | |
* Author: [email protected] | |
************************************************************************/ | |
#include <chrono> | |
class Timing | |
{ | |
public: | |
Timing(); | |
~Timing(); | |
void startTiming(); | |
void stopTiming(); | |
double getEllipsedMilliseconds(); | |
private: | |
inline void setToCurrentTime(std::chrono::high_resolution_clock::time_point & timePoint); | |
std::chrono::high_resolution_clock::time_point m_startTime; | |
std::chrono::high_resolution_clock::time_point m_endTime; | |
bool m_running = false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment