17be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes/* 27be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes * Copyright (C) 2012 The Android Open Source Project 37be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes * 47be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 57be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes * you may not use this file except in compliance with the License. 67be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes * You may obtain a copy of the License at 77be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes * 87be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 97be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes * 107be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes * Unless required by applicable law or agreed to in writing, software 117be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 127be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes * See the License for the specific language governing permissions and 147be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes * limitations under the License. 157be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes */ 167be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes 177be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes#include <stdint.h> 187be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes 197be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes#include <vector> 207be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes 217be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughesnamespace testing { 227be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes 237be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughesclass Benchmark { 247be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes public: 257be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes Benchmark(const char* name, void (*fn)(int)) { 267be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes Register(name, fn, NULL); 277be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes } 287be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes 297be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes Benchmark(const char* name, void (*fn_range)(int, int)) { 307be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes Register(name, NULL, fn_range); 317be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes } 327be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes 337be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes Benchmark* Arg(int x); 347be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes 359edb3e004b487e08cbbb54f2af18b15241550513Elliott Hughes const char* Name(); 369edb3e004b487e08cbbb54f2af18b15241550513Elliott Hughes 377be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes bool ShouldRun(int argc, char* argv[]); 387be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes void Run(); 397be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes 407be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes private: 417be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes const char* name_; 427be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes 437be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes void (*fn_)(int); 447be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes void (*fn_range_)(int, int); 457be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes 467be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes std::vector<int> args_; 477be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes 487be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes void Register(const char* name, void (*fn)(int), void (*fn_range)(int, int)); 497be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes void RunRepeatedlyWithArg(int iterations, int arg); 507be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes void RunWithArg(int arg); 517be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes}; 527be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes 537be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes} // namespace testing 547be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes 557be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughesvoid SetBenchmarkBytesProcessed(int64_t); 567be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughesvoid StopBenchmarkTiming(); 577be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughesvoid StartBenchmarkTiming(); 587be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes 597be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes#define BENCHMARK(f) \ 607be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes static ::testing::Benchmark* _benchmark_##f __attribute__((unused)) = \ 617be369d4c60e9df2316fdb6c73181a40020abef2Elliott Hughes (new ::testing::Benchmark(#f, f)) 62