Last active
August 30, 2020 16:36
-
-
Save inxanedev/5ffa50831c549602169a1a9b7d50824f to your computer and use it in GitHub Desktop.
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
#include <iostream> | |
#include <thread> | |
#include <chrono> | |
double benchmark(void (*f)()) { | |
auto start = std::chrono::high_resolution_clock::now(); | |
// Call the function | |
(*f)(); | |
auto end = std::chrono::high_resolution_clock::now(); | |
// Subtract times and return result as a double | |
std::chrono::duration<double> dur = end - start; | |
return dur.count(); | |
} | |
// Function to benchmark | |
void func() { | |
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); | |
} | |
int main() { | |
double duration = benchmark(func); | |
std::cout << duration << std::endl; | |
std::cin.get(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment