Created
September 2, 2016 17:57
-
-
Save danielkraic/f567a3d023517692cb6fb15854f5bc9f to your computer and use it in GitHub Desktop.
google benchmark c++ example
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 <sstream> | |
#include <benchmark/benchmark.h> | |
using namespace std; | |
static void BM_bench01(benchmark::State& st) { | |
while (st.KeepRunning()) { | |
std::stringstream s; | |
for (size_t i = 0; i < st.range(0); i++) { | |
s << "nemam cas " << i << '\n'; | |
} | |
auto str = s.str(); | |
} | |
} | |
static void BM_bench02(benchmark::State& st) { | |
while (st.KeepRunning()) { | |
std::stringstream s; | |
for (size_t i = 0; i < st.range(0); i++) { | |
s << "nemam cas " << i << std::endl; | |
} | |
auto str = s.str(); | |
} | |
} | |
static void BM_bench03(benchmark::State& st) { | |
while (st.KeepRunning()) { | |
std::string s; | |
for (size_t i = 0; i < st.range(0); i++) { | |
s += "nemam cas " + std::to_string(i) + "\n"; | |
} | |
} | |
} | |
BENCHMARK(BM_bench01)->RangeMultiplier(2)->Range(8, 8<<10);; | |
BENCHMARK(BM_bench02)->RangeMultiplier(2)->Range(8, 8<<10);; | |
BENCHMARK(BM_bench03)->RangeMultiplier(2)->Range(8, 8<<10);; | |
BENCHMARK_MAIN(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment