Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: third_party/google_benchmark/test/multiple_ranges_test.cc

Issue 2865663003: Adding Google benchmarking library. (Closed)
Patch Set: Sketch. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #include "benchmark/benchmark.h"
2
3 #include <cassert>
4 #include <set>
5
6 class MultipleRangesFixture : public ::benchmark::Fixture {
7 public:
8 MultipleRangesFixture()
9 : expectedValues({{1, 3, 5},
10 {1, 3, 8},
11 {1, 3, 15},
12 {2, 3, 5},
13 {2, 3, 8},
14 {2, 3, 15},
15 {1, 4, 5},
16 {1, 4, 8},
17 {1, 4, 15},
18 {2, 4, 5},
19 {2, 4, 8},
20 {2, 4, 15},
21 {1, 7, 5},
22 {1, 7, 8},
23 {1, 7, 15},
24 {2, 7, 5},
25 {2, 7, 8},
26 {2, 7, 15},
27 {7, 6, 3}}) {}
28
29 void SetUp(const ::benchmark::State& state) {
30 std::vector<int> ranges = {state.range(0), state.range(1), state.range(2)};
31
32 assert(expectedValues.find(ranges) != expectedValues.end());
33
34 actualValues.insert(ranges);
35 }
36
37 virtual ~MultipleRangesFixture() {
38 assert(actualValues.size() == expectedValues.size());
39 }
40
41 std::set<std::vector<int>> expectedValues;
42 std::set<std::vector<int>> actualValues;
43 };
44
45 BENCHMARK_DEFINE_F(MultipleRangesFixture, Empty)(benchmark::State& state) {
46 while (state.KeepRunning()) {
47 int product = state.range(0) * state.range(1) * state.range(2);
48 for (int x = 0; x < product; x++) {
49 benchmark::DoNotOptimize(x);
50 }
51 }
52 }
53
54 BENCHMARK_REGISTER_F(MultipleRangesFixture, Empty)
55 ->RangeMultiplier(2)
56 ->Ranges({{1, 2}, {3, 7}, {5, 15}})
57 ->Args({7, 6, 3});
58
59 void BM_CheckDefaultArgument(benchmark::State& state) {
60 // Test that the 'range()' without an argument is the same as 'range(0)'.
61 assert(state.range() == state.range(0));
62 assert(state.range() != state.range(1));
63 while (state.KeepRunning()) {
64 }
65 }
66 BENCHMARK(BM_CheckDefaultArgument)->Ranges({{1, 5}, {6, 10}});
67
68 static void BM_MultipleRanges(benchmark::State& st) {
69 while (st.KeepRunning()) {
70 }
71 }
72 BENCHMARK(BM_MultipleRanges)->Ranges({{5, 5}, {6, 6}});
73
74 BENCHMARK_MAIN()
OLDNEW
« no previous file with comments | « third_party/google_benchmark/test/map_test.cc ('k') | third_party/google_benchmark/test/options_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698