xref: /aosp_15_r20/external/regex-re2/util/benchmark.h (revision ccdc9c3e24c519bfa4832a66aa2e83a52c19f295)
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 UTIL_BENCHMARK_H_
6 #define UTIL_BENCHMARK_H_
7 
8 #include <stdint.h>
9 
10 namespace testing {
11 struct Benchmark {
12   const char* name;
13   void (*fn)(int);
14   void (*fnr)(int, int);
15   int lo;
16   int hi;
17   int threadlo;
18   int threadhi;
19 
20   void Register();
BenchmarkBenchmark21   Benchmark(const char* name, void (*f)(int)) { Clear(name); fn = f; Register(); }
BenchmarkBenchmark22   Benchmark(const char* name, void (*f)(int, int), int l, int h) { Clear(name); fnr = f; lo = l; hi = h; Register(); }
ClearBenchmark23   void Clear(const char* n) { name = n; fn = 0; fnr = 0; lo = 0; hi = 0; threadlo = 0; threadhi = 0; }
ThreadRangeBenchmark24   Benchmark* ThreadRange(int lo, int hi) { threadlo = lo; threadhi = hi; return this; }
25 };
26 }  // namespace testing
27 
28 void SetBenchmarkBytesProcessed(int64_t);
29 void StopBenchmarkTiming();
30 void StartBenchmarkTiming();
31 void BenchmarkMemoryUsage();
32 void SetBenchmarkItemsProcessed(int);
33 
34 int NumCPUs();
35 
36 #define BENCHMARK(f) \
37 	::testing::Benchmark* _benchmark_##f = (new ::testing::Benchmark(#f, f))
38 
39 #define BENCHMARK_RANGE(f, lo, hi) \
40 	::testing::Benchmark* _benchmark_##f = \
41 	(new ::testing::Benchmark(#f, f, lo, hi))
42 
43 #endif  // UTIL_BENCHMARK_H_
44