Commit 17e1c405 by Marek Kurdej

Add ArgName() and ArgNames() methods to name arguments/ranges.

parent 44c25c89
...@@ -510,6 +510,13 @@ class Benchmark { ...@@ -510,6 +510,13 @@ class Benchmark {
// REQUIRES: The function passed to the constructor must accept arg1, arg2 ... // REQUIRES: The function passed to the constructor must accept arg1, arg2 ...
Benchmark* Ranges(const std::vector<std::pair<int, int> >& ranges); Benchmark* Ranges(const std::vector<std::pair<int, int> >& ranges);
// Equivalent to ArgNames({name})
Benchmark* ArgName(const std::string& name);
// Set the argument names to display in the benchmark name. If not called,
// only argument values will be shown.
Benchmark* ArgNames(const std::vector<std::string>& names);
// Equivalent to Ranges({{lo1, hi1}, {lo2, hi2}}). // Equivalent to Ranges({{lo1, hi1}, {lo2, hi2}}).
// NOTE: This is a legacy C++03 interface provided for compatibility only. // NOTE: This is a legacy C++03 interface provided for compatibility only.
// New code should use 'Ranges'. // New code should use 'Ranges'.
...@@ -526,8 +533,7 @@ class Benchmark { ...@@ -526,8 +533,7 @@ class Benchmark {
Benchmark* Apply(void (*func)(Benchmark* benchmark)); Benchmark* Apply(void (*func)(Benchmark* benchmark));
// Set the range multiplier for non-dense range. If not called, the range // Set the range multiplier for non-dense range. If not called, the range
// multiplier // multiplier kRangeMultiplier will be used.
// kRangeMultiplier will be used.
Benchmark* RangeMultiplier(int multiplier); Benchmark* RangeMultiplier(int multiplier);
// Set the minimum amount of time to use when running this benchmark. This // Set the minimum amount of time to use when running this benchmark. This
...@@ -618,6 +624,7 @@ class Benchmark { ...@@ -618,6 +624,7 @@ class Benchmark {
std::string name_; std::string name_;
ReportMode report_mode_; ReportMode report_mode_;
std::vector<std::string> arg_names_; // Args for all benchmark runs
std::vector<std::vector<int> > args_; // Args for all benchmark runs std::vector<std::vector<int> > args_; // Args for all benchmark runs
TimeUnit time_unit_; TimeUnit time_unit_;
int range_multiplier_; int range_multiplier_;
......
...@@ -151,8 +151,16 @@ bool BenchmarkFamilies::FindBenchmarks( ...@@ -151,8 +151,16 @@ bool BenchmarkFamilies::FindBenchmarks(
instance.threads = num_threads; instance.threads = num_threads;
// Add arguments to instance name // Add arguments to instance name
size_t arg_i = 0;
for (auto const& arg : args) { for (auto const& arg : args) {
if (arg_i < family->arg_names_.size()) {
instance.name +=
StringPrintF("/%s:", family->arg_names_[arg_i].c_str());
} else {
instance.name += "/";
}
AppendHumanReadable(arg, &instance.name); AppendHumanReadable(arg, &instance.name);
++arg_i;
} }
if (!IsZero(family->min_time_)) { if (!IsZero(family->min_time_)) {
...@@ -293,6 +301,16 @@ Benchmark* Benchmark::Ranges(const std::vector<std::pair<int, int>>& ranges) { ...@@ -293,6 +301,16 @@ Benchmark* Benchmark::Ranges(const std::vector<std::pair<int, int>>& ranges) {
return this; return this;
} }
Benchmark* Benchmark::ArgName(const std::string& name) {
arg_names_ = {name};
return this;
}
Benchmark* Benchmark::ArgNames(const std::vector<std::string>& names) {
arg_names_ = names;
return this;
}
Benchmark* Benchmark::DenseRange(int start, int limit, int step) { Benchmark* Benchmark::DenseRange(int start, int limit, int step) {
CHECK(ArgsCnt() == -1 || ArgsCnt() == 1); CHECK(ArgsCnt() == -1 || ArgsCnt() == 1);
CHECK_GE(start, 0); CHECK_GE(start, 0);
......
...@@ -107,7 +107,7 @@ std::string ToBinaryStringFullySpecified(double value, double threshold, ...@@ -107,7 +107,7 @@ std::string ToBinaryStringFullySpecified(double value, double threshold,
void AppendHumanReadable(int n, std::string* str) { void AppendHumanReadable(int n, std::string* str) {
std::stringstream ss; std::stringstream ss;
// Round down to the nearest SI prefix. // Round down to the nearest SI prefix.
ss << "/" << ToBinaryStringFullySpecified(n, 1.0, 0); ss << ToBinaryStringFullySpecified(n, 1.0, 0);
*str += ss.str(); *str += ss.str();
} }
......
...@@ -52,6 +52,46 @@ ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_error\",$"}, ...@@ -52,6 +52,46 @@ ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_error\",$"},
ADD_CASES(TC_CSVOut, {{"^\"BM_error\",,,,,,,,true,\"message\"$"}}); ADD_CASES(TC_CSVOut, {{"^\"BM_error\",,,,,,,,true,\"message\"$"}});
// ========================================================================= // // ========================================================================= //
// ------------------------ Testing No Arg Name Output -----------------------
// //
// ========================================================================= //
void BM_no_arg_name(benchmark::State& state) {
while (state.KeepRunning()) {
}
}
BENCHMARK(BM_no_arg_name)->Arg(3);
ADD_CASES(TC_ConsoleOut, {{"^BM_no_arg_name/3 %console_report$"}});
ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_no_arg_name/3\",$"}});
ADD_CASES(TC_CSVOut, {{"^\"BM_no_arg_name/3\",%csv_report$"}});
// ========================================================================= //
// ------------------------ Testing Arg Name Output ----------------------- //
// ========================================================================= //
void BM_arg_name(benchmark::State& state) {
while (state.KeepRunning()) {
}
}
BENCHMARK(BM_arg_name)->Arg(3)->ArgName("first");
ADD_CASES(TC_ConsoleOut, {{"^BM_arg_name/first:3 %console_report$"}});
ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_arg_name/first:3\",$"}});
ADD_CASES(TC_CSVOut, {{"^\"BM_arg_name/first:3\",%csv_report$"}});
// ========================================================================= //
// ------------------------ Testing Arg Names Output ----------------------- //
// ========================================================================= //
void BM_arg_names(benchmark::State& state) {
while (state.KeepRunning()) {
}
}
BENCHMARK(BM_arg_names)->Args({2, 4})->ArgNames({"first", "second"});
ADD_CASES(TC_ConsoleOut, {{"^BM_arg_names/first:2/second:4 %console_report$"}});
ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_arg_names/first:2/second:4\",$"}});
ADD_CASES(TC_CSVOut, {{"^\"BM_arg_names/first:2/second:4\",%csv_report$"}});
// ========================================================================= //
// ----------------------- Testing Complexity Output ----------------------- // // ----------------------- Testing Complexity 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