Last active
May 14, 2024 14:32
-
-
Save Infinitusvoid/8cae70f2a80e57ad45be4b2be554437c to your computer and use it in GitHub Desktop.
C++ : Timing
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 <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