bionic benchmarks: export benchmark library
Export libbenchmark for external projects to write benchmarks against. Change-Id: I3b04a56a62ce517afc0d5e06dc8d28879ada3d30
This commit is contained in:

committed by
Elliott Hughes

parent
6fac2f680f
commit
7b9df19491
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "benchmark.h"
|
||||
#include <benchmark.h>
|
||||
|
||||
#include <regex.h>
|
||||
#include <stdio.h>
|
||||
@@ -29,11 +29,15 @@
|
||||
static int64_t g_bytes_processed;
|
||||
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;
|
||||
static BenchmarkMap g_benchmarks;
|
||||
static int g_name_column_width = 20;
|
||||
|
||||
static BenchmarkMap& Benchmarks() {
|
||||
static BenchmarkMap benchmarks;
|
||||
return benchmarks;
|
||||
}
|
||||
|
||||
static int Round(int n) {
|
||||
int base = 1;
|
||||
@@ -98,7 +102,7 @@ void Benchmark::Register(const char* name, void (*fn)(int), void (*fn_range)(int
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
g_benchmarks.insert(std::make_pair(name, this));
|
||||
Benchmarks().insert(std::make_pair(name, this));
|
||||
}
|
||||
|
||||
void Benchmark::Run() {
|
||||
@@ -191,18 +195,18 @@ void StartBenchmarkTiming() {
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (g_benchmarks.empty()) {
|
||||
if (Benchmarks().empty()) {
|
||||
fprintf(stderr, "No benchmarks registered!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (BenchmarkMapIt it = g_benchmarks.begin(); it != g_benchmarks.end(); ++it) {
|
||||
for (BenchmarkMapIt it = Benchmarks().begin(); it != Benchmarks().end(); ++it) {
|
||||
int name_width = static_cast<int>(strlen(it->second->Name()));
|
||||
g_name_column_width = std::max(g_name_column_width, name_width);
|
||||
}
|
||||
|
||||
bool need_header = true;
|
||||
for (BenchmarkMapIt it = g_benchmarks.begin(); it != g_benchmarks.end(); ++it) {
|
||||
for (BenchmarkMapIt it = Benchmarks().begin(); it != Benchmarks().end(); ++it) {
|
||||
::testing::Benchmark* b = it->second;
|
||||
if (b->ShouldRun(argc, argv)) {
|
||||
if (need_header) {
|
||||
@@ -217,7 +221,7 @@ int main(int argc, char* argv[]) {
|
||||
if (need_header) {
|
||||
fprintf(stderr, "No matching benchmarks!\n");
|
||||
fprintf(stderr, "Available benchmarks:\n");
|
||||
for (BenchmarkMapIt it = g_benchmarks.begin(); it != g_benchmarks.end(); ++it) {
|
||||
for (BenchmarkMapIt it = Benchmarks().begin(); it != Benchmarks().end(); ++it) {
|
||||
fprintf(stderr, " %s\n", it->second->Name());
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
|
Reference in New Issue
Block a user