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;
}
exit(EXIT_FAILURE);
}
- Benchmarks().insert(std::make_pair(name, this));
+ Benchmarks().push_back(this);
}
void Benchmark::Run() {
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");
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);
}