Allow wildcards to match arg values.
Change-Id: I38230b500bb8f8f69af0d7c740855a401cd12898
diff --git a/benchmarks/benchmark/Benchmark.h b/benchmarks/benchmark/Benchmark.h
index 16ae5fa..ae5c1a2 100644
--- a/benchmarks/benchmark/Benchmark.h
+++ b/benchmarks/benchmark/Benchmark.h
@@ -34,27 +34,29 @@
virtual std::string Name() = 0;
- virtual void RunAll() = 0;
-
- bool ShouldRun(std::vector<regex_t*>&);
+ virtual size_t RunAllArgs(std::vector<regex_t*>&) = 0;
void SetBenchmarkBytesProcessed(uint64_t bytes) { bytes_processed_ += bytes; }
void StopBenchmarkTiming();
void StartBenchmarkTiming();
// Run all of the benchmarks that have registered.
- static bool RunAll(std::vector<regex_t*>&);
+ static size_t RunAll(std::vector<regex_t*>&);
static std::vector<Benchmark*>& List();
static int MaxNameColumnWidth();
protected:
- virtual int NameColumnWidth() = 0;
+ virtual size_t NameColumnWidth() = 0;
uint64_t bytes_processed_;
uint64_t total_time_ns_;
uint64_t start_time_ns_;
+
+ static bool header_printed_;
+
+ static void PrintHeader();
};
template <typename T>
@@ -64,6 +66,7 @@
virtual ~BenchmarkT() {}
protected:
+ bool ShouldRun(std::vector<regex_t*>&, T arg);
void RunWithArg(T arg);
virtual void RunIterations(int, T) = 0;
virtual std::string GetNameStr(T) = 0;
@@ -75,8 +78,14 @@
virtual ~BenchmarkWithoutArg() {}
protected:
- virtual void RunAll() override {
- RunWithArg(nullptr);
+ virtual size_t RunAllArgs(std::vector<regex_t*>& regs) override {
+ size_t benchmarks_run = 0;
+ if (BenchmarkT<void*>::ShouldRun(regs, nullptr)) {
+ PrintHeader();
+ RunWithArg(nullptr);
+ benchmarks_run++;
+ }
+ return benchmarks_run;
}
virtual void RunIterations(int iters, void*) override {
@@ -85,8 +94,8 @@
virtual void Run(int) = 0;
- virtual int NameColumnWidth() override {
- return (int)Name().size();
+ virtual size_t NameColumnWidth() override {
+ return Name().size();
}
virtual std::string GetNameStr(void *) override;
@@ -104,20 +113,26 @@
}
protected:
- virtual int NameColumnWidth() override {
- int max = 0;
- for (const auto arg : args_) {
- max = std::max(max, (int)GetNameStr(arg).size());
+ virtual size_t NameColumnWidth() override {
+ size_t max = 0;
+ for (const auto& arg : args_) {
+ max = std::max(max, GetNameStr(arg).size());
}
return max;
}
std::string GetNameStr(T arg) override;
- virtual void RunAll() override {
- for (T arg : args_) {
- BenchmarkT<T>::RunWithArg(arg);
+ virtual size_t RunAllArgs(std::vector<regex_t*>& regs) override {
+ size_t benchmarks_run = 0;
+ for (T& arg : args_) {
+ if (BenchmarkT<T>::ShouldRun(regs, arg)) {
+ Benchmark::PrintHeader();
+ BenchmarkT<T>::RunWithArg(arg);
+ benchmarks_run++;
+ }
}
+ return benchmarks_run;
}
virtual void RunIterations(int iters, T arg) override {