Skip to content

Instantly share code, notes, and snippets.

@alekswn
Created November 21, 2015 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alekswn/19354ee12a36b07215c8 to your computer and use it in GitHub Desktop.
Save alekswn/19354ee12a36b07215c8 to your computer and use it in GitHub Desktop.
Dawn easy benchmark for C++
#ifdef BENCH
#include <ctime>
#include <chrono>
#define BENCHMARK_START \
auto t_start = std::chrono::high_resolution_clock::now(); \
std::clock_t c_start = std::clock();
#define BENCHMARK_FINISH( OUT_STREAM, NAME ) \
std::clock_t c_end = std::clock(); \
auto t_end = std::chrono::high_resolution_clock::now(); \
OUT_STREAM << "BENCHMARK \"" << NAME << "\" : " \
<< std::fixed << "CPU time: " \
<< 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC << " ms; " \
<< "Wall time: " \
<< std::chrono::duration<double, std::milli>(t_end-t_start).count() \
<< " ms\n";
#else
#define BENCHMARK_START
#define BENCHMARK_FINISH( OUT_STREAM, NAME )
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment