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

Side by Side Diff: third_party/google_benchmark/test/fixture_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
2 #include "benchmark/benchmark.h"
3
4 #include <cassert>
5 #include <memory>
6
7 class MyFixture : public ::benchmark::Fixture {
8 public:
9 void SetUp(const ::benchmark::State& state) {
10 if (state.thread_index == 0) {
11 assert(data.get() == nullptr);
12 data.reset(new int(42));
13 }
14 }
15
16 void TearDown(const ::benchmark::State& state) {
17 if (state.thread_index == 0) {
18 assert(data.get() != nullptr);
19 data.reset();
20 }
21 }
22
23 ~MyFixture() { assert(data == nullptr); }
24
25 std::unique_ptr<int> data;
26 };
27
28 BENCHMARK_F(MyFixture, Foo)(benchmark::State &st) {
29 assert(data.get() != nullptr);
30 assert(*data == 42);
31 while (st.KeepRunning()) {
32 }
33 }
34
35 BENCHMARK_DEFINE_F(MyFixture, Bar)(benchmark::State& st) {
36 if (st.thread_index == 0) {
37 assert(data.get() != nullptr);
38 assert(*data == 42);
39 }
40 while (st.KeepRunning()) {
41 assert(data.get() != nullptr);
42 assert(*data == 42);
43 }
44 st.SetItemsProcessed(st.range(0));
45 }
46 BENCHMARK_REGISTER_F(MyFixture, Bar)->Arg(42);
47 BENCHMARK_REGISTER_F(MyFixture, Bar)->Arg(42)->ThreadPerCpu();
48
49 BENCHMARK_MAIN()
OLDNEW
« no previous file with comments | « third_party/google_benchmark/test/filter_test.cc ('k') | third_party/google_benchmark/test/map_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698