Skip to content

Instantly share code, notes, and snippets.

@Infinitusvoid
Last active May 14, 2024 14:32
Show Gist options
  • Save Infinitusvoid/8cae70f2a80e57ad45be4b2be554437c to your computer and use it in GitHub Desktop.
Save Infinitusvoid/8cae70f2a80e57ad45be4b2be554437c to your computer and use it in GitHub Desktop.
C++ : Timing
#include <iostream>
#include <chrono>
#include <thread>
struct Timer
{
std::chrono::time_point<std::chrono::steady_clock> start, end;
std::chrono::duration<float> duration;
Timer()
{
start = std::chrono::high_resolution_clock::now();
}
~Timer()
{
end = std::chrono::high_resolution_clock::now();
duration = end - start;
float ms = duration.count() * 1000.0f;
std::cout << "Timer took " << ms << "ms" << std::endl;
}
};
void Function()
{
Timer timer;
for (int i = 0; i < 100; i++)
std::cout << "Hello\n";
}
int main()
{
Function();
std::cin.get();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment