diff options
author | Colin Cross <ccross@android.com> | 2013-11-15 14:34:22 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-01-15 16:22:42 -0800 |
commit | 7b9df19491ead673084902f6d79eebd8d192d5c6 (patch) | |
tree | 50e2f361777743fd706718a37fac7b0fe03c8e61 /benchmarks/include | |
parent | 6fac2f680f829570122276dc6876f02350a652b1 (diff) | |
download | bionic-7b9df19491ead673084902f6d79eebd8d192d5c6.zip bionic-7b9df19491ead673084902f6d79eebd8d192d5c6.tar.gz bionic-7b9df19491ead673084902f6d79eebd8d192d5c6.tar.bz2 |
bionic benchmarks: export benchmark library
Export libbenchmark for external projects to write benchmarks against.
Change-Id: I3b04a56a62ce517afc0d5e06dc8d28879ada3d30
Diffstat (limited to 'benchmarks/include')
-rw-r--r-- | benchmarks/include/benchmark.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/benchmarks/include/benchmark.h b/benchmarks/include/benchmark.h new file mode 100644 index 0000000..7e134a0 --- /dev/null +++ b/benchmarks/include/benchmark.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BENCHMARKS_BENCHMARK_H_ +#define BENCHMARKS_BENCHMARK_H_ + +#include <stdint.h> +#include <vector> + +namespace testing { + +class Benchmark { + public: + Benchmark(const char* name, void (*fn)(int)) { + Register(name, fn, NULL); + } + + Benchmark(const char* name, void (*fn_range)(int, int)) { + Register(name, NULL, fn_range); + } + + Benchmark* Arg(int x); + + const char* Name(); + + bool ShouldRun(int argc, char* argv[]); + void Run(); + + private: + const char* name_; + + void (*fn_)(int); + void (*fn_range_)(int, int); + + std::vector<int> args_; + + void Register(const char* name, void (*fn)(int), void (*fn_range)(int, int)); + void RunRepeatedlyWithArg(int iterations, int arg); + void RunWithArg(int arg); +}; + +} // namespace testing + +void SetBenchmarkBytesProcessed(int64_t); +void StopBenchmarkTiming(); +void StartBenchmarkTiming(); + +#define BENCHMARK(f) \ + static ::testing::Benchmark* _benchmark_##f __attribute__((unused)) = \ + (new ::testing::Benchmark(#f, f)) + +#endif |