Skip to content

Commit 51a4fa0

Browse files
committed
some upgrades
1. move the definition of callback_function to the benchmark namespace. in order for the user to use this 2. add overloads for Stup/Teardown
1 parent a27e122 commit 51a4fa0

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

include/benchmark/benchmark.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
304304

305305
namespace benchmark {
306306
class BenchmarkReporter;
307+
class State;
308+
309+
// Define alias of Setup/Teardown callback function type
310+
using callback_function = std::function<void(const benchmark::State&)>;
307311

308312
// Default number of minimum benchmark running time in seconds.
309313
const char kDefaultMinTimeStr[] = "0.5s";
@@ -1080,9 +1084,6 @@ class BENCHMARK_EXPORT Benchmark {
10801084
public:
10811085
virtual ~Benchmark();
10821086

1083-
// Define alias of Setup/Teardown callback function type
1084-
using callback_function = std::function<void(const benchmark::State&)>;
1085-
10861087
// Note: the following methods all return "this" so that multiple
10871088
// method calls can be chained together in one expression.
10881089

@@ -1164,7 +1165,9 @@ class BENCHMARK_EXPORT Benchmark {
11641165
//
11651166
// The callback must not be NULL or self-deleting.
11661167
Benchmark* Setup(callback_function&&);
1168+
Benchmark* Setup(const callback_function&);
11671169
Benchmark* Teardown(callback_function&&);
1170+
Benchmark* Teardown(const callback_function&);
11681171

11691172
// Pass this benchmark object to *func, which can customize
11701173
// the benchmark by calling various methods like Arg, Args,

src/benchmark_api_internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class BenchmarkInstance {
6868
IterationCount iterations_;
6969
int threads_; // Number of concurrent threads to us
7070

71-
using callback_function = Benchmark::callback_function;
7271
callback_function setup_ = nullptr;
7372
callback_function teardown_ = nullptr;
7473
};

src/benchmark_register.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,24 @@ Benchmark* Benchmark::Setup(callback_function&& setup) {
343343
return this;
344344
}
345345

346+
Benchmark* Benchmark::Setup(const callback_function& setup) {
347+
BM_CHECK(setup != nullptr);
348+
setup_ = std::move(setup);
349+
return this;
350+
}
351+
346352
Benchmark* Benchmark::Teardown(callback_function&& teardown) {
347353
BM_CHECK(teardown != nullptr);
348354
teardown_ = std::forward<callback_function>(teardown);
349355
return this;
350356
}
351357

358+
Benchmark* Benchmark::Teardown(const callback_function& teardown) {
359+
BM_CHECK(teardown != nullptr);
360+
teardown_ = teardown;
361+
return this;
362+
}
363+
352364
Benchmark* Benchmark::RangeMultiplier(int multiplier) {
353365
BM_CHECK(multiplier > 1);
354366
range_multiplier_ = multiplier;

0 commit comments

Comments
 (0)