Skip to content

Instantly share code, notes, and snippets.

@EricWF
Created October 2, 2015 09:34
Show Gist options
  • Select an option

  • Save EricWF/29868ce86eaa4a03132d to your computer and use it in GitHub Desktop.

Select an option

Save EricWF/29868ce86eaa4a03132d to your computer and use it in GitHub Desktop.
results in 32 bit mode
#include "benchmark/benchmark.h"
#include <cstdint>
#include <limits>
using namespace benchmark;
typedef std::uint32_t UInt32;
typedef std::uint64_t UInt64;
template <class IntType>
void BM_IntAddingAndComparisons(State& st) {
//Use the upper bits of the IntType to try and defeat the optimizer.
IntType const Iters = 10000000;
IntType const Max = std::numeric_limits<IntType>::max();
IntType const Stop = Max - Iters;
while (st.KeepRunning()) {
for (IntType i = Stop; i != Max; ++i) {
DoNotOptimize(i);
}
}
}
BENCHMARK_TEMPLATE(BM_IntAddingAndComparisons, UInt32);
BENCHMARK_TEMPLATE(BM_IntAddingAndComparisons, UInt64);
BENCHMARK_MAIN()
Run on (8 X 4228.74 MHz CPU s)
2015-10-02 03:06:55
Benchmark Time(ns) CPU(ns) Iterations
-------------------------------------------------------------------
BM_IntAddingAndComparisons<UInt32> 5063790 5066026 833
BM_IntAddingAndComparisons<UInt64> 6406909 6406015 665
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment