1 // Copyright 2009 The RE2 Authors. All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #ifndef RE2_UTIL_BENCHMARK_H__ 6 #define RE2_UTIL_BENCHMARK_H__ 7 8 namespace testing { 9 struct Benchmark { 10 const char* name; 11 void (*fn)(int); 12 void (*fnr)(int, int); 13 int lo; 14 int hi; 15 int threadlo; 16 int threadhi; 17 18 void Register(); 19 Benchmark(const char* name, void (*f)(int)) { Clear(name); fn = f; Register(); } 20 Benchmark(const char* name, void (*f)(int, int), int l, int h) { Clear(name); fnr = f; lo = l; hi = h; Register(); } 21 void Clear(const char* n) { name = n; fn = 0; fnr = 0; lo = 0; hi = 0; threadlo = 0; threadhi = 0; } 22 Benchmark* ThreadRange(int lo, int hi) { threadlo = lo; threadhi = hi; return this; } 23 }; 24 } // namespace testing 25 26 void SetBenchmarkBytesProcessed(long long); 27 void StopBenchmarkTiming(); 28 void StartBenchmarkTiming(); 29 void BenchmarkMemoryUsage(); 30 void SetBenchmarkItemsProcessed(int); 31 32 int NumCPUs(); 33 34 #define BENCHMARK(f) \ 35 ::testing::Benchmark* _benchmark_##f = (new ::testing::Benchmark(#f, f)) 36 37 #define BENCHMARK_RANGE(f, lo, hi) \ 38 ::testing::Benchmark* _benchmark_##f = \ 39 (new ::testing::Benchmark(#f, f, lo, hi)) 40 41 #endif // RE2_UTIL_BENCHMARK_H__ 42