Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Colin Cross | 7b9df19 | 2013-11-15 14:34:22 -0800 | [diff] [blame] | 17 | #ifndef BENCHMARKS_BENCHMARK_H_ |
| 18 | #define BENCHMARKS_BENCHMARK_H_ |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 19 | |
Colin Cross | 7b9df19 | 2013-11-15 14:34:22 -0800 | [diff] [blame] | 20 | #include <stdint.h> |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
| 23 | namespace testing { |
| 24 | |
| 25 | class Benchmark { |
| 26 | public: |
| 27 | Benchmark(const char* name, void (*fn)(int)) { |
| 28 | Register(name, fn, NULL); |
| 29 | } |
| 30 | |
| 31 | Benchmark(const char* name, void (*fn_range)(int, int)) { |
| 32 | Register(name, NULL, fn_range); |
| 33 | } |
| 34 | |
| 35 | Benchmark* Arg(int x); |
| 36 | |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 37 | const char* Name(); |
| 38 | |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 39 | bool ShouldRun(int argc, char* argv[]); |
| 40 | void Run(); |
| 41 | |
| 42 | private: |
| 43 | const char* name_; |
| 44 | |
| 45 | void (*fn_)(int); |
| 46 | void (*fn_range_)(int, int); |
| 47 | |
| 48 | std::vector<int> args_; |
| 49 | |
| 50 | void Register(const char* name, void (*fn)(int), void (*fn_range)(int, int)); |
| 51 | void RunRepeatedlyWithArg(int iterations, int arg); |
| 52 | void RunWithArg(int arg); |
| 53 | }; |
| 54 | |
| 55 | } // namespace testing |
| 56 | |
| 57 | void SetBenchmarkBytesProcessed(int64_t); |
| 58 | void StopBenchmarkTiming(); |
| 59 | void StartBenchmarkTiming(); |
| 60 | |
| 61 | #define BENCHMARK(f) \ |
| 62 | static ::testing::Benchmark* _benchmark_##f __attribute__((unused)) = \ |
| 63 | (new ::testing::Benchmark(#f, f)) |
Colin Cross | 7b9df19 | 2013-11-15 14:34:22 -0800 | [diff] [blame] | 64 | |
| 65 | #endif |