Created
June 30, 2023 22:40
-
-
Save esnosy/73e7c534e0f29e0e97049b5bce0543b5 to your computer and use it in GitHub Desktop.
Neat TIMER macro for C++11
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
# GPLv3 iyadahmed430@gmail.com (Iyad Ahmed) | |
#pragma once | |
#include <chrono> | |
#include <functional> | |
void time_function(const char *message, std::function<void()> function) | |
{ | |
auto start = std::chrono::high_resolution_clock::now(); | |
function(); | |
auto end = std::chrono::high_resolution_clock::now(); | |
std::cout << message << " took " | |
<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" | |
<< std::endl; | |
} | |
#define TIMER(message, code) time_function(message, [&]() { code }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment