-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
115 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "profiling.h" | ||
#include "timing.h" | ||
#include <cassert> | ||
#include <iostream> | ||
|
||
void ProfileTimer::StartInvocation() | ||
{ | ||
m_startTime = Time::GetTime(); | ||
} | ||
|
||
void ProfileTimer::StopInvocation() | ||
{ | ||
if(m_startTime == 0) | ||
{ | ||
std::cout << "Error: StopInvocation called without matching start invocation" << std::endl; | ||
assert(m_startTime != 0); | ||
} | ||
|
||
m_numInvocations++; | ||
m_totalTime += (Time::GetTime() - m_startTime); | ||
m_startTime = 0; | ||
} | ||
|
||
double ProfileTimer::GetTimeAndReset(double dividend) | ||
{ | ||
dividend = (dividend == 0) ? m_numInvocations : dividend; | ||
double result = (m_totalTime == 0 && dividend == 0.0) ? 0.0 : (1000.0 * m_totalTime)/((double)dividend); | ||
m_totalTime = 0.0; | ||
m_numInvocations = 0; | ||
|
||
return result; | ||
} | ||
|
||
double ProfileTimer::DisplayAndReset(const std::string& message, double dividend, int displayedMessageLength) | ||
{ | ||
std::string whiteSpace = ""; | ||
for(int i = message.length(); i < displayedMessageLength; i++) | ||
{ | ||
whiteSpace += " "; | ||
} | ||
|
||
double time = GetTimeAndReset(dividend); | ||
std::cout << message << whiteSpace << time << " ms" << std::endl; | ||
return time; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef PROFILING_H_INCLUDED | ||
#define PROFILING_H_INCLUDED | ||
|
||
#include <string> | ||
|
||
class ProfileTimer | ||
{ | ||
public: | ||
ProfileTimer() : | ||
m_numInvocations(0), | ||
m_totalTime(0.0), | ||
m_startTime(0) {} | ||
|
||
void StartInvocation(); | ||
void StopInvocation(); | ||
|
||
double DisplayAndReset(const std::string& message, double dividend = 0, int displayedMessageLength = 40); | ||
double GetTimeAndReset(double dividend = 0); | ||
protected: | ||
private: | ||
int m_numInvocations; | ||
double m_totalTime; | ||
double m_startTime; | ||
}; | ||
|
||
#endif // PROFILING_H_INCLUDED |
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
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