diff options
author | 2016-03-12 12:31:13 +0100 | |
---|---|---|
committer | 2016-03-12 12:31:13 +0100 | |
commit | a026a582f1a0ea8c1ede3acaddacef506ef3f3b0 (patch) | |
tree | e31573822f2359677de519f9f3b600d98e8764cd /3rdparty/benchmark/test/fixture_test.cc | |
parent | 477d2abd43984f076b7e45f5527591fa8fd0d241 (diff) | |
parent | dcab55bf53b94713a6f72e9633f5101c8dd6c08c (diff) |
Merge pull request #15 from mamedev/master
Sync to base master
Diffstat (limited to '3rdparty/benchmark/test/fixture_test.cc')
-rw-r--r-- | 3rdparty/benchmark/test/fixture_test.cc | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/3rdparty/benchmark/test/fixture_test.cc b/3rdparty/benchmark/test/fixture_test.cc index 8aea6ef0601..bf800fda20d 100644 --- a/3rdparty/benchmark/test/fixture_test.cc +++ b/3rdparty/benchmark/test/fixture_test.cc @@ -2,41 +2,51 @@ #include "benchmark/benchmark.h" #include <cassert> - -class MyFixture : public ::benchmark::Fixture -{ -public: - void SetUp() { - data = new int(42); +#include <memory> + +class MyFixture : public ::benchmark::Fixture { + public: + void SetUp(const ::benchmark::State& state) { + if (state.thread_index == 0) { + assert(data.get() == nullptr); + data.reset(new int(42)); } + } - void TearDown() { - assert(data != nullptr); - delete data; - data = nullptr; + void TearDown(const ::benchmark::State& state) { + if (state.thread_index == 0) { + assert(data.get() != nullptr); + data.reset(); } + } - ~MyFixture() { - assert(data == nullptr); - } + ~MyFixture() { + assert(data == nullptr); + } - int* data; + std::unique_ptr<int> data; }; BENCHMARK_F(MyFixture, Foo)(benchmark::State& st) { - assert(data != nullptr); - assert(*data == 42); - while (st.KeepRunning()) { - } + assert(data.get() != nullptr); + assert(*data == 42); + while (st.KeepRunning()) { + } } BENCHMARK_DEFINE_F(MyFixture, Bar)(benchmark::State& st) { + if (st.thread_index == 0) { + assert(data.get() != nullptr); + assert(*data == 42); + } while (st.KeepRunning()) { + assert(data.get() != nullptr); + assert(*data == 42); } st.SetItemsProcessed(st.range_x()); } BENCHMARK_REGISTER_F(MyFixture, Bar)->Arg(42); - +BENCHMARK_REGISTER_F(MyFixture, Bar)->Arg(42)->ThreadPerCpu(); BENCHMARK_MAIN() |