Skip to content

Instantly share code, notes, and snippets.

@tmathews
Created December 11, 2024 17:02
Show Gist options
  • Save tmathews/a83f8864b8d97943472fa0cb66aa7493 to your computer and use it in GitHub Desktop.
Save tmathews/a83f8864b8d97943472fa0cb66aa7493 to your computer and use it in GitHub Desktop.
struct StopWatch {
std::string label;
std::chrono::steady_clock::time_point start;
std::chrono::steady_clock::time_point finish;
StopWatch()
{
start = std::chrono::steady_clock::now();
}
StopWatch(const char *str)
{
label = str;
start = std::chrono::steady_clock::now();
}
void Start()
{
start = std::chrono::steady_clock::now();
};
std::chrono::duration<double, std::milli> Stop()
{
finish = std::chrono::steady_clock::now();
std::chrono::duration<double, std::milli> ms_double = finish - start;
return ms_double;
};
void PrintEllapsed(const char *sublabel)
{
auto now = std::chrono::steady_clock::now();
std::chrono::duration<double, std::milli> ms_double = now - start;
std::cout << label << sublabel << ms_double.count() << '\n';
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment