I've put some work into the Google Benchmark library in order to make it easier to benchmark libc++. These changes have already been upstreamed into Google Benchmark and this patch applies the changes to the in-tree version. The main improvement in the addition of a 'compare_bench.py' script which makes it very easy to compare benchmarks. For example to compare the native STL to libc++ you would run: `$ compare_bench.py ./util_smartptr.native.out ./util_smartptr.libcxx.out` And the output would look like: RUNNING: ./util_smartptr.native.out Benchmark Time CPU Iterations ---------------------------------------------------------------- BM_SharedPtrCreateDestroy 62 ns 62 ns 10937500 BM_SharedPtrIncDecRef 31 ns 31 ns 23972603 BM_WeakPtrIncDecRef 28 ns 28 ns 23648649 RUNNING: ./util_smartptr.libcxx.out Benchmark Time CPU Iterations ---------------------------------------------------------------- BM_SharedPtrCreateDestroy 46 ns 46 ns 14957265 BM_SharedPtrIncDecRef 31 ns 31 ns 22435897 BM_WeakPtrIncDecRef 34 ns 34 ns 21084337 Comparing ./util_smartptr.native.out to ./util_smartptr.libcxx.out Benchmark Time CPU ----------------------------------------------------- BM_SharedPtrCreateDestroy -0.26 -0.26 BM_SharedPtrIncDecRef +0.00 +0.00 BM_WeakPtrIncDecRef +0.21 +0.21 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@278147 91177308-0d34-0410-b5e6-96231b3b80d8
47 lines
1.3 KiB
C++
47 lines
1.3 KiB
C++
#include "benchmark/benchmark.h"
|
|
|
|
#include <set>
|
|
#include <cassert>
|
|
|
|
class MultipleRangesFixture : public ::benchmark::Fixture {
|
|
public:
|
|
MultipleRangesFixture()
|
|
: expectedValues({
|
|
{1, 3, 5}, {1, 3, 8}, {1, 3, 15}, {2, 3, 5}, {2, 3, 8}, {2, 3, 15},
|
|
{1, 4, 5}, {1, 4, 8}, {1, 4, 15}, {2, 4, 5}, {2, 4, 8}, {2, 4, 15},
|
|
{1, 7, 5}, {1, 7, 8}, {1, 7, 15}, {2, 7, 5}, {2, 7, 8}, {2, 7, 15},
|
|
{7, 6, 3}
|
|
})
|
|
{
|
|
}
|
|
|
|
void SetUp(const ::benchmark::State& state) {
|
|
std::vector<int> ranges = {state.range(0), state.range(1), state.range(2)};
|
|
|
|
assert(expectedValues.find(ranges) != expectedValues.end());
|
|
|
|
actualValues.insert(ranges);
|
|
}
|
|
|
|
virtual ~MultipleRangesFixture() {
|
|
assert(actualValues.size() == expectedValues.size());
|
|
}
|
|
|
|
std::set<std::vector<int>> expectedValues;
|
|
std::set<std::vector<int>> actualValues;
|
|
};
|
|
|
|
|
|
BENCHMARK_DEFINE_F(MultipleRangesFixture, Empty)(benchmark::State& state) {
|
|
while (state.KeepRunning()) {
|
|
int product = state.range(0) * state.range(1) * state.range(2);
|
|
for (int x = 0; x < product; x++) {
|
|
benchmark::DoNotOptimize(x);
|
|
}
|
|
}
|
|
}
|
|
|
|
BENCHMARK_REGISTER_F(MultipleRangesFixture, Empty)->RangeMultiplier(2)->Ranges({{1, 2}, {3, 7}, {5, 15}})->Args({7, 6, 3});
|
|
|
|
BENCHMARK_MAIN()
|