summaryrefslogtreecommitdiffstats
path: root/benchmarks
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-01-16 03:22:40 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-01-16 03:22:40 +0000
commitffad8df672363bad43528898cc47aa2ed3d08c66 (patch)
tree2d2cd3d820388e3931e6f958d229f8d183ea326b /benchmarks
parent594db0f1b235306d2687395564745888348df808 (diff)
parente48f533c95cba673244444ee5444dc95a5cb2fdb (diff)
downloadbionic-ffad8df672363bad43528898cc47aa2ed3d08c66.zip
bionic-ffad8df672363bad43528898cc47aa2ed3d08c66.tar.gz
bionic-ffad8df672363bad43528898cc47aa2ed3d08c66.tar.bz2
Merge "Use a vector of benchmarks and new for loop syntax."
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/benchmark_main.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/benchmarks/benchmark_main.cpp b/benchmarks/benchmark_main.cpp
index e922e1e..6d83f8a 100644
--- a/benchmarks/benchmark_main.cpp
+++ b/benchmarks/benchmark_main.cpp
@@ -31,11 +31,10 @@ static int64_t g_benchmark_total_time_ns;
static int64_t g_benchmark_start_time_ns;
static int g_name_column_width = 20;
-typedef std::map<std::string, ::testing::Benchmark*> BenchmarkMap;
-typedef BenchmarkMap::iterator BenchmarkMapIt;
+typedef std::vector<::testing::Benchmark*> BenchmarkList;
-static BenchmarkMap& Benchmarks() {
- static BenchmarkMap benchmarks;
+static BenchmarkList& Benchmarks() {
+ static BenchmarkList benchmarks;
return benchmarks;
}
@@ -102,7 +101,7 @@ void Benchmark::Register(const char* name, void (*fn)(int), void (*fn_range)(int
exit(EXIT_FAILURE);
}
- Benchmarks().insert(std::make_pair(name, this));
+ Benchmarks().push_back(this);
}
void Benchmark::Run() {
@@ -204,14 +203,13 @@ int main(int argc, char* argv[]) {
exit(EXIT_FAILURE);
}
- for (BenchmarkMapIt it = Benchmarks().begin(); it != Benchmarks().end(); ++it) {
- int name_width = static_cast<int>(strlen(it->second->Name()));
+ for (auto& b : Benchmarks()) {
+ int name_width = static_cast<int>(strlen(b->Name()));
g_name_column_width = std::max(g_name_column_width, name_width);
}
bool need_header = true;
- for (BenchmarkMapIt it = Benchmarks().begin(); it != Benchmarks().end(); ++it) {
- ::testing::Benchmark* b = it->second;
+ for (auto& b : Benchmarks()) {
if (b->ShouldRun(argc, argv)) {
if (need_header) {
printf("%-*s %10s %10s\n", g_name_column_width, "", "iterations", "ns/op");
@@ -225,8 +223,8 @@ int main(int argc, char* argv[]) {
if (need_header) {
fprintf(stderr, "No matching benchmarks!\n");
fprintf(stderr, "Available benchmarks:\n");
- for (BenchmarkMapIt it = Benchmarks().begin(); it != Benchmarks().end(); ++it) {
- fprintf(stderr, " %s\n", it->second->Name());
+ for (auto& b : Benchmarks()) {
+ fprintf(stderr, " %s\n", b->Name());
}
exit(EXIT_FAILURE);
}