blob: 31bbd5348aee9bb86bfa521ca5cb5a5f51b8ba80 [file] [log] [blame]
Ian Hodson2ee91b42012-05-14 12:29:36 +01001// 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
8namespace testing {
9struct 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
26void SetBenchmarkBytesProcessed(long long);
27void StopBenchmarkTiming();
28void StartBenchmarkTiming();
29void BenchmarkMemoryUsage();
30void SetBenchmarkItemsProcessed(int);
31
32int 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__