summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/benchmark/test/fixture_test.cc
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/benchmark/test/fixture_test.cc')
-rw-r--r--3rdparty/benchmark/test/fixture_test.cc48
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()