Unverified Commit 5e387e7d by Tobias Schmidt Committed by GitHub

Implement custom benchmark name (#1107)

* Implement custom benchmark name The benchmark's name can be changed using the Name() function which internally uses SetName(). * Update AUTHORS and CONTRIBUTORS * Describe new feature in README * Move new name function up Fixes #1106
parent cc9abfc8
...@@ -52,6 +52,7 @@ Sayan Bhattacharjee <aero.sayan@gmail.com> ...@@ -52,6 +52,7 @@ Sayan Bhattacharjee <aero.sayan@gmail.com>
Shuo Chen <chenshuo@chenshuo.com> Shuo Chen <chenshuo@chenshuo.com>
Steinar H. Gunderson <sgunderson@bigfoot.com> Steinar H. Gunderson <sgunderson@bigfoot.com>
Stripe, Inc. Stripe, Inc.
Tobias Schmidt <tobias.schmidt@in.tum.de>
Yixuan Qiu <yixuanq@gmail.com> Yixuan Qiu <yixuanq@gmail.com>
Yusuke Suzuki <utatane.tea@gmail.com> Yusuke Suzuki <utatane.tea@gmail.com>
Zbigniew Skowron <zbychs@gmail.com> Zbigniew Skowron <zbychs@gmail.com>
......
...@@ -75,6 +75,7 @@ Roman Lebedev <lebedev.ri@gmail.com> ...@@ -75,6 +75,7 @@ Roman Lebedev <lebedev.ri@gmail.com>
Sayan Bhattacharjee <aero.sayan@gmail.com> Sayan Bhattacharjee <aero.sayan@gmail.com>
Shuo Chen <chenshuo@chenshuo.com> Shuo Chen <chenshuo@chenshuo.com>
Steven Wan <wan.yu@ibm.com> Steven Wan <wan.yu@ibm.com>
Tobias Schmidt <tobias.schmidt@in.tum.de>
Tobias Ulvgård <tobias.ulvgard@dirac.se> Tobias Ulvgård <tobias.ulvgard@dirac.se>
Tom Madams <tom.ej.madams@gmail.com> <tmadams@google.com> Tom Madams <tom.ej.madams@gmail.com> <tmadams@google.com>
Yixuan Qiu <yixuanq@gmail.com> Yixuan Qiu <yixuanq@gmail.com>
......
...@@ -278,6 +278,8 @@ too (`-lkstat`). ...@@ -278,6 +278,8 @@ too (`-lkstat`).
[Passing Arguments](#passing-arguments) [Passing Arguments](#passing-arguments)
[Custom Benchmark Name](#custom-benchmark-name)
[Calculating Asymptotic Complexity](#asymptotic-complexity) [Calculating Asymptotic Complexity](#asymptotic-complexity)
[Templated Benchmarks](#templated-benchmarks) [Templated Benchmarks](#templated-benchmarks)
...@@ -652,6 +654,19 @@ BENCHMARK(BM_StringCompare)->RangeMultiplier(2) ...@@ -652,6 +654,19 @@ BENCHMARK(BM_StringCompare)->RangeMultiplier(2)
->Range(1<<10, 1<<18)->Complexity([](benchmark::IterationCount n)->double{return n; }); ->Range(1<<10, 1<<18)->Complexity([](benchmark::IterationCount n)->double{return n; });
``` ```
<a name="custom-benchmark-name" />
### Custom Benchmark Name
You can change the benchmark's name as follows:
```c++
BENCHMARK(BM_memcpy)->Name("memcpy")->RangeMultiplier(2)->Range(8, 8<<10);
```
The invocation will execute the benchmark as before using `BM_memcpy` but changes
the prefix in the report to `memcpy`.
<a name="templated-benchmarks" /> <a name="templated-benchmarks" />
### Templated Benchmarks ### Templated Benchmarks
......
...@@ -790,6 +790,9 @@ class Benchmark { ...@@ -790,6 +790,9 @@ class Benchmark {
// Note: the following methods all return "this" so that multiple // Note: the following methods all return "this" so that multiple
// method calls can be chained together in one expression. // method calls can be chained together in one expression.
// Specify the name of the benchmark
Benchmark* Name(const std::string& name);
// Run this benchmark once with "x" as the extra argument passed // Run this benchmark once with "x" as the extra argument passed
// to the function. // to the function.
// REQUIRES: The function passed to the constructor must accept an arg1. // REQUIRES: The function passed to the constructor must accept an arg1.
......
...@@ -278,6 +278,11 @@ Benchmark::Benchmark(const char* name) ...@@ -278,6 +278,11 @@ Benchmark::Benchmark(const char* name)
Benchmark::~Benchmark() {} Benchmark::~Benchmark() {}
Benchmark* Benchmark::Name(const std::string& name) {
SetName(name.c_str());
return this;
}
Benchmark* Benchmark::Arg(int64_t x) { Benchmark* Benchmark::Arg(int64_t x) {
CHECK(ArgsCnt() == -1 || ArgsCnt() == 1); CHECK(ArgsCnt() == -1 || ArgsCnt() == 1);
args_.push_back({x}); args_.push_back({x});
......
...@@ -335,6 +335,30 @@ ADD_CASES(TC_JSONOut, ...@@ -335,6 +335,30 @@ ADD_CASES(TC_JSONOut,
ADD_CASES(TC_CSVOut, {{"^\"BM_arg_names/first:2/5/third:4\",%csv_report$"}}); ADD_CASES(TC_CSVOut, {{"^\"BM_arg_names/first:2/5/third:4\",%csv_report$"}});
// ========================================================================= // // ========================================================================= //
// ------------------------ Testing Name Output ---------------------------- //
// ========================================================================= //
void BM_name(benchmark::State& state) {
for (auto _ : state) {
}
}
BENCHMARK(BM_name)->Name("BM_custom_name");
ADD_CASES(TC_ConsoleOut, {{"^BM_custom_name %console_report$"}});
ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_custom_name\",$"},
{"\"run_name\": \"BM_custom_name\",$", MR_Next},
{"\"run_type\": \"iteration\",$", MR_Next},
{"\"repetitions\": 0,$", MR_Next},
{"\"repetition_index\": 0,$", MR_Next},
{"\"threads\": 1,$", MR_Next},
{"\"iterations\": %int,$", MR_Next},
{"\"real_time\": %float,$", MR_Next},
{"\"cpu_time\": %float,$", MR_Next},
{"\"time_unit\": \"ns\"$", MR_Next},
{"}", MR_Next}});
ADD_CASES(TC_CSVOut, {{"^\"BM_custom_name\",%csv_report$"}});
// ========================================================================= //
// ------------------------ Testing Big Args Output ------------------------ // // ------------------------ Testing Big Args Output ------------------------ //
// ========================================================================= // // ========================================================================= //
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment