aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--CONTRIBUTORS1
-rw-r--r--README.md15
-rw-r--r--include/benchmark/benchmark.h3
-rw-r--r--src/benchmark_register.cc5
-rw-r--r--test/reporter_output_test.cc24
6 files changed, 49 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
index 3068b2e..9b98041 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -52,6 +52,7 @@ Sayan Bhattacharjee <aero.sayan@gmail.com>
Shuo Chen <chenshuo@chenshuo.com>
Steinar H. Gunderson <sgunderson@bigfoot.com>
Stripe, Inc.
+Tobias Schmidt <tobias.schmidt@in.tum.de>
Yixuan Qiu <yixuanq@gmail.com>
Yusuke Suzuki <utatane.tea@gmail.com>
Zbigniew Skowron <zbychs@gmail.com>
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index b5e1aa4..8370a2d 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -75,6 +75,7 @@ Roman Lebedev <lebedev.ri@gmail.com>
Sayan Bhattacharjee <aero.sayan@gmail.com>
Shuo Chen <chenshuo@chenshuo.com>
Steven Wan <wan.yu@ibm.com>
+Tobias Schmidt <tobias.schmidt@in.tum.de>
Tobias Ulvgård <tobias.ulvgard@dirac.se>
Tom Madams <tom.ej.madams@gmail.com> <tmadams@google.com>
Yixuan Qiu <yixuanq@gmail.com>
diff --git a/README.md b/README.md
index 43b77ca..0d827b8 100644
--- a/README.md
+++ b/README.md
@@ -278,6 +278,8 @@ too (`-lkstat`).
[Passing Arguments](#passing-arguments)
+[Custom Benchmark Name](#custom-benchmark-name)
+
[Calculating Asymptotic Complexity](#asymptotic-complexity)
[Templated Benchmarks](#templated-benchmarks)
@@ -652,6 +654,19 @@ BENCHMARK(BM_StringCompare)->RangeMultiplier(2)
->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" />
### Templated Benchmarks
diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h
index f57e3e7..2e714b6 100644
--- a/include/benchmark/benchmark.h
+++ b/include/benchmark/benchmark.h
@@ -790,6 +790,9 @@ class Benchmark {
// Note: the following methods all return "this" so that multiple
// 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
// to the function.
// REQUIRES: The function passed to the constructor must accept an arg1.
diff --git a/src/benchmark_register.cc b/src/benchmark_register.cc
index 65d9944..c007876 100644
--- a/src/benchmark_register.cc
+++ b/src/benchmark_register.cc
@@ -278,6 +278,11 @@ Benchmark::Benchmark(const char* name)
Benchmark::~Benchmark() {}
+Benchmark* Benchmark::Name(const std::string& name) {
+ SetName(name.c_str());
+ return this;
+}
+
Benchmark* Benchmark::Arg(int64_t x) {
CHECK(ArgsCnt() == -1 || ArgsCnt() == 1);
args_.push_back({x});
diff --git a/test/reporter_output_test.cc b/test/reporter_output_test.cc
index d24a57d..b3d8edb 100644
--- a/test/reporter_output_test.cc
+++ b/test/reporter_output_test.cc
@@ -335,6 +335,30 @@ ADD_CASES(TC_JSONOut,
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 ------------------------ //
// ========================================================================= //