Skip to content

Instantly share code, notes, and snippets.

@Izaron
Last active September 1, 2018 22:52
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 Izaron/f756cb6a85e42a13480b688825766de8 to your computer and use it in GitHub Desktop.
Save Izaron/f756cb6a85e42a13480b688825766de8 to your computer and use it in GitHub Desktop.
// Compile me! Using:
// g++ benchmark.cpp -std=c++11 -lbenchmark -lpthread -O2 -o benchmark
#include <benchmark/benchmark.h>
#include <boost/dynamic_bitset.hpp>
template <typename Bitset> Bitset GenerateBitset(size_t size) {
Bitset bs(size);
for (size_t i = 0; i < size; ++i)
bs.set(i, (rand() % 2) == 0);
return bs;
}
template <typename Bitset> void BM_DynBitsetCount(benchmark::State& state) {
for (auto _ : state) {
state.PauseTiming();
auto bs = GenerateBitset<Bitset>(state.range(0));
state.ResumeTiming();
for (int j = 0; j < state.range(1); ++j)
benchmark::DoNotOptimize(bs.count());
}
}
#define BT(Block) BENCHMARK_TEMPLATE(BM_DynBitsetCount, \
boost::dynamic_bitset<Block>) \
->Args({1<<10, 1<<15}) \
->Args({1<<10, 1<<18}) \
->Args({1<<10, 1<<20}) \
->Args({1<<12, 1<<15}) \
->Args({1<<12, 1<<18}) \
->Args({1<<12, 1<<20}) \
->Args({1<<13, 1<<15}) \
->Args({1<<13, 1<<18}) \
->Args({1<<13, 1<<20}) \
BT(unsigned char);
BT(unsigned short);
BT(unsigned int);
BT(unsigned long);
BT(unsigned long long);
BENCHMARK_MAIN();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment