summaryrefslogtreecommitdiffstats
path: root/benchmarks
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-01-15 17:10:42 -0800
committerElliott Hughes <enh@google.com>2015-01-15 17:10:42 -0800
commite48f533c95cba673244444ee5444dc95a5cb2fdb (patch)
tree2d2cd3d820388e3931e6f958d229f8d183ea326b /benchmarks
parent594db0f1b235306d2687395564745888348df808 (diff)
downloadbionic-e48f533c95cba673244444ee5444dc95a5cb2fdb.zip
bionic-e48f533c95cba673244444ee5444dc95a5cb2fdb.tar.gz
bionic-e48f533c95cba673244444ee5444dc95a5cb2fdb.tar.bz2
Use a vector of benchmarks and new for loop syntax.
Change-Id: Ib1f1250e7786770083ed6a478677a893b2075a93
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);
}