Skip to content

Instantly share code, notes, and snippets.

@shikharbhardwaj
Last active May 16, 2017 16:17
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 shikharbhardwaj/6f5a48075ae964c294b775a6c153a6bd to your computer and use it in GitHub Desktop.
Save shikharbhardwaj/6f5a48075ae964c294b775a6c153a6bd to your computer and use it in GitHub Desktop.
λ spike/parallel ∴ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
λ spike/parallel ∴ g++ test_bench.cpp -std=c++11 -O3 -Wall -Werror -lbenchmark -lpthread
λ spike/parallel ∴ ./a.out
Run on (4 X 3700 MHz CPU s)
2017-05-16 21:42:29
Benchmark Time CPU Iterations
--------------------------------------------------------
BM_TimeDiffTOD 18 ns 18 ns 39517679
BM_TimeDiffChrono 19 ns 19 ns 35092984
#include <benchmark/benchmark.h>
#include <chrono>
#include <sys/time.h>
static void BM_TimeDiffChrono(benchmark::State& state) {
while (state.KeepRunning()){
benchmark::DoNotOptimize(std::chrono::high_resolution_clock::now());
}
}
static void BM_TimeDiffTOD(benchmark::State& state) {
while (state.KeepRunning()){
struct timeval tval;
benchmark::DoNotOptimize(gettimeofday(&tval, NULL));
}
}
BENCHMARK(BM_TimeDiffTOD);
BENCHMARK(BM_TimeDiffChrono);
BENCHMARK_MAIN();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment