benchmark.h
Go to the documentation of this file.
1 // Copyright 2015 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // Support for registering benchmarks for functions.
16 
17 /* Example usage:
18 // Define a function that executes the code to be measured a
19 // specified number of times:
20 static void BM_StringCreation(benchmark::State& state) {
21  while (state.KeepRunning())
22  std::string empty_string;
23 }
24 
25 // Register the function as a benchmark
26 BENCHMARK(BM_StringCreation);
27 
28 // Define another benchmark
29 static void BM_StringCopy(benchmark::State& state) {
30  std::string x = "hello";
31  while (state.KeepRunning())
32  std::string copy(x);
33 }
34 BENCHMARK(BM_StringCopy);
35 
36 // Augment the main() program to invoke benchmarks if specified
37 // via the --benchmarks command line flag. E.g.,
38 // my_unittest --benchmark_filter=all
39 // my_unittest --benchmark_filter=BM_StringCreation
40 // my_unittest --benchmark_filter=String
41 // my_unittest --benchmark_filter='Copy|Creation'
42 int main(int argc, char** argv) {
43  benchmark::Initialize(&argc, argv);
44  benchmark::RunSpecifiedBenchmarks();
45  return 0;
46 }
47 
48 // Sometimes a family of microbenchmarks can be implemented with
49 // just one routine that takes an extra argument to specify which
50 // one of the family of benchmarks to run. For example, the following
51 // code defines a family of microbenchmarks for measuring the speed
52 // of memcpy() calls of different lengths:
53 
54 static void BM_memcpy(benchmark::State& state) {
55  char* src = new char[state.range(0)]; char* dst = new char[state.range(0)];
56  memset(src, 'x', state.range(0));
57  while (state.KeepRunning())
58  memcpy(dst, src, state.range(0));
59  state.SetBytesProcessed(int64_t(state.iterations()) *
60  int64_t(state.range(0)));
61  delete[] src; delete[] dst;
62 }
63 BENCHMARK(BM_memcpy)->Arg(8)->Arg(64)->Arg(512)->Arg(1<<10)->Arg(8<<10);
64 
65 // The preceding code is quite repetitive, and can be replaced with the
66 // following short-hand. The following invocation will pick a few
67 // appropriate arguments in the specified range and will generate a
68 // microbenchmark for each such argument.
69 BENCHMARK(BM_memcpy)->Range(8, 8<<10);
70 
71 // You might have a microbenchmark that depends on two inputs. For
72 // example, the following code defines a family of microbenchmarks for
73 // measuring the speed of set insertion.
74 static void BM_SetInsert(benchmark::State& state) {
75  while (state.KeepRunning()) {
76  state.PauseTiming();
77  set<int> data = ConstructRandomSet(state.range(0));
78  state.ResumeTiming();
79  for (int j = 0; j < state.range(1); ++j)
80  data.insert(RandomNumber());
81  }
82 }
83 BENCHMARK(BM_SetInsert)
84  ->Args({1<<10, 1})
85  ->Args({1<<10, 8})
86  ->Args({1<<10, 64})
87  ->Args({1<<10, 512})
88  ->Args({8<<10, 1})
89  ->Args({8<<10, 8})
90  ->Args({8<<10, 64})
91  ->Args({8<<10, 512});
92 
93 // The preceding code is quite repetitive, and can be replaced with
94 // the following short-hand. The following macro will pick a few
95 // appropriate arguments in the product of the two specified ranges
96 // and will generate a microbenchmark for each such pair.
97 BENCHMARK(BM_SetInsert)->Ranges({{1<<10, 8<<10}, {1, 512}});
98 
99 // For more complex patterns of inputs, passing a custom function
100 // to Apply allows programmatic specification of an
101 // arbitrary set of arguments to run the microbenchmark on.
102 // The following example enumerates a dense range on
103 // one parameter, and a sparse range on the second.
104 static void CustomArguments(benchmark::internal::Benchmark* b) {
105  for (int i = 0; i <= 10; ++i)
106  for (int j = 32; j <= 1024*1024; j *= 8)
107  b->Args({i, j});
108 }
109 BENCHMARK(BM_SetInsert)->Apply(CustomArguments);
110 
111 // Templated microbenchmarks work the same way:
112 // Produce then consume 'size' messages 'iters' times
113 // Measures throughput in the absence of multiprogramming.
114 template <class Q> int BM_Sequential(benchmark::State& state) {
115  Q q;
116  typename Q::value_type v;
117  while (state.KeepRunning()) {
118  for (int i = state.range(0); i--; )
119  q.push(v);
120  for (int e = state.range(0); e--; )
121  q.Wait(&v);
122  }
123  // actually messages, not bytes:
124  state.SetBytesProcessed(
125  static_cast<int64_t>(state.iterations())*state.range(0));
126 }
127 BENCHMARK_TEMPLATE(BM_Sequential, WaitQueue<int>)->Range(1<<0, 1<<10);
128 
129 Use `Benchmark::MinTime(double t)` to set the minimum time used to run the
130 benchmark. This option overrides the `benchmark_min_time` flag.
131 
132 void BM_test(benchmark::State& state) {
133  ... body ...
134 }
135 BENCHMARK(BM_test)->MinTime(2.0); // Run for at least 2 seconds.
136 
137 In a multithreaded test, it is guaranteed that none of the threads will start
138 until all have called KeepRunning, and all will have finished before KeepRunning
139 returns false. As such, any global setup or teardown you want to do can be
140 wrapped in a check against the thread index:
141 
142 static void BM_MultiThreaded(benchmark::State& state) {
143  if (state.thread_index == 0) {
144  // Setup code here.
145  }
146  while (state.KeepRunning()) {
147  // Run the test as normal.
148  }
149  if (state.thread_index == 0) {
150  // Teardown code here.
151  }
152 }
153 BENCHMARK(BM_MultiThreaded)->Threads(4);
154 
155 
156 If a benchmark runs a few milliseconds it may be hard to visually compare the
157 measured times, since the output data is given in nanoseconds per default. In
158 order to manually set the time unit, you can specify it manually:
159 
160 BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
161 */
162 
163 #ifndef BENCHMARK_BENCHMARK_H_
164 #define BENCHMARK_BENCHMARK_H_
165 
166 
167 #if __cplusplus >= 201103L
168 #define BENCHMARK_HAS_CXX11
169 #endif
170 
171 #include <stdint.h>
172 
173 #include <cassert>
174 #include <cstddef>
175 #include <iosfwd>
176 #include <string>
177 #include <vector>
178 #include <map>
179 #include <set>
180 
181 #if defined(BENCHMARK_HAS_CXX11)
182 #include <type_traits>
183 #include <initializer_list>
184 #include <utility>
185 #endif
186 
187 #if defined(_MSC_VER)
188 #include <intrin.h> // for _ReadWriteBarrier
189 #endif
190 
191 #ifndef BENCHMARK_HAS_CXX11
192 #define BENCHMARK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
193  TypeName(const TypeName&); \
194  TypeName& operator=(const TypeName&)
195 #else
196 #define BENCHMARK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
197  TypeName(const TypeName&) = delete; \
198  TypeName& operator=(const TypeName&) = delete
199 #endif
200 
201 #if defined(__GNUC__)
202 #define BENCHMARK_UNUSED __attribute__((unused))
203 #define BENCHMARK_ALWAYS_INLINE __attribute__((always_inline))
204 #define BENCHMARK_NOEXCEPT noexcept
205 #define BENCHMARK_NOEXCEPT_OP(x) noexcept(x)
206 #elif defined(_MSC_VER) && !defined(__clang__)
207 #define BENCHMARK_UNUSED
208 #define BENCHMARK_ALWAYS_INLINE __forceinline
209 #if _MSC_VER >= 1900
210 #define BENCHMARK_NOEXCEPT noexcept
211 #define BENCHMARK_NOEXCEPT_OP(x) noexcept(x)
212 #else
213 #define BENCHMARK_NOEXCEPT
214 #define BENCHMARK_NOEXCEPT_OP(x)
215 #endif
216 #define __func__ __FUNCTION__
217 #else
218 #define BENCHMARK_UNUSED
219 #define BENCHMARK_ALWAYS_INLINE
220 #define BENCHMARK_NOEXCEPT
221 #define BENCHMARK_NOEXCEPT_OP(x)
222 #endif
223 
224 #define BENCHMARK_INTERNAL_TOSTRING2(x) #x
225 #define BENCHMARK_INTERNAL_TOSTRING(x) BENCHMARK_INTERNAL_TOSTRING2(x)
226 
227 #if defined(__GNUC__)
228 #define BENCHMARK_BUILTIN_EXPECT(x, y) __builtin_expect(x, y)
229 #define BENCHMARK_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
230 #else
231 #define BENCHMARK_BUILTIN_EXPECT(x, y) x
232 #define BENCHMARK_DEPRECATED_MSG(msg)
233 #define BENCHMARK_WARNING_MSG(msg) __pragma(message(__FILE__ "(" BENCHMARK_INTERNAL_TOSTRING(__LINE__) ") : warning note: " msg))
234 #endif
235 
236 #if defined(__GNUC__) && !defined(__clang__)
237 #define BENCHMARK_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
238 #endif
239 
240 
241 namespace benchmark {
242 class BenchmarkReporter;
243 
244 void Initialize(int* argc, char** argv);
245 
246 // Report to stdout all arguments in 'argv' as unrecognized except the first.
247 // Returns true there is at least on unrecognized argument (i.e. 'argc' > 1).
248 bool ReportUnrecognizedArguments(int argc, char** argv);
249 
250 // Generate a list of benchmarks matching the specified --benchmark_filter flag
251 // and if --benchmark_list_tests is specified return after printing the name
252 // of each matching benchmark. Otherwise run each matching benchmark and
253 // report the results.
254 //
255 // The second and third overload use the specified 'console_reporter' and
256 // 'file_reporter' respectively. 'file_reporter' will write to the file
257 // specified
258 // by '--benchmark_output'. If '--benchmark_output' is not given the
259 // 'file_reporter' is ignored.
260 //
261 // RETURNS: The number of matching benchmarks.
262 size_t RunSpecifiedBenchmarks();
263 size_t RunSpecifiedBenchmarks(BenchmarkReporter* console_reporter);
264 size_t RunSpecifiedBenchmarks(BenchmarkReporter* console_reporter,
265  BenchmarkReporter* file_reporter);
266 
267 // If this routine is called, peak memory allocation past this point in the
268 // benchmark is reported at the end of the benchmark report line. (It is
269 // computed by running the benchmark once with a single iteration and a memory
270 // tracer.)
271 // TODO(dominic)
272 // void MemoryUsage();
273 
274 namespace internal {
275 class Benchmark;
276 class BenchmarkImp;
277 class BenchmarkFamilies;
278 
279 void UseCharPointer(char const volatile*);
280 
281 // Take ownership of the pointer and register the benchmark. Return the
282 // registered benchmark.
284 
285 // Ensure that the standard streams are properly initialized in every TU.
286 int InitializeStreams();
288 
289 } // namespace internal
290 
291 
292 #if !defined(__GNUC__) || defined(__pnacl__) || defined(EMSCRIPTN)
293 # define BENCHMARK_HAS_NO_INLINE_ASSEMBLY
294 #endif
295 
296 // The DoNotOptimize(...) function can be used to prevent a value or
297 // expression from being optimized away by the compiler. This function is
298 // intended to add little to no overhead.
299 // See: https://youtu.be/nXaxk27zwlk?t=2441
300 #ifndef BENCHMARK_HAS_NO_INLINE_ASSEMBLY
301 template <class Tp>
302 inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
303  // Clang doesn't like the 'X' constraint on `value` and certain GCC versions
304  // don't like the 'g' constraint. Attempt to placate them both.
305 #if defined(__clang__)
306  asm volatile("" : : "g"(value) : "memory");
307 #else
308  asm volatile("" : : "i,r,m"(value) : "memory");
309 #endif
310 }
311 // Force the compiler to flush pending writes to global memory. Acts as an
312 // effective read/write barrier
313 inline BENCHMARK_ALWAYS_INLINE void ClobberMemory() {
314  asm volatile("" : : : "memory");
315 }
316 #elif defined(_MSC_VER)
317 template <class Tp>
318 inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
319  internal::UseCharPointer(&reinterpret_cast<char const volatile&>(value));
320  _ReadWriteBarrier();
321 }
322 
323 inline BENCHMARK_ALWAYS_INLINE void ClobberMemory() {
324  _ReadWriteBarrier();
325 }
326 #else
327 template <class Tp>
329  internal::UseCharPointer(&reinterpret_cast<char const volatile&>(value));
330 }
331 // FIXME Add ClobberMemory() for non-gnu and non-msvc compilers
332 #endif
333 
334 
335 
336 // This class is used for user-defined counters.
337 class Counter {
338 public:
339 
340  enum Flags {
342  // Mark the counter as a rate. It will be presented divided
343  // by the duration of the benchmark.
344  kIsRate = 1,
345  // Mark the counter as a thread-average quantity. It will be
346  // presented divided by the number of threads.
348  // Mark the counter as a thread-average rate. See above.
350  };
351 
352  double value;
354 
356  Counter(double v = 0., Flags f = kDefaults) : value(v), flags(f) {}
357 
358  BENCHMARK_ALWAYS_INLINE operator double const& () const { return value; }
359  BENCHMARK_ALWAYS_INLINE operator double & () { return value; }
360 
361 };
362 
363 // This is the container for the user-defined counters.
364 typedef std::map<std::string, Counter> UserCounters;
365 
366 
367 // TimeUnit is passed to a benchmark in order to specify the order of magnitude
368 // for the measured time.
370 
371 // BigO is passed to a benchmark in order to specify the asymptotic
372 // computational
373 // complexity for the benchmark. In case oAuto is selected, complexity will be
374 // calculated automatically to the best fit.
376 
377 // BigOFunc is passed to a benchmark in order to specify the asymptotic
378 // computational complexity for the benchmark.
379 typedef double(BigOFunc)(int);
380 
381 namespace internal {
382 class ThreadTimer;
383 class ThreadManager;
384 
386 #if defined(BENCHMARK_HAS_CXX11)
387  : unsigned
388 #else
389 #endif
390  {
391  RM_Unspecified, // The mode has not been manually specified
392  RM_Default, // The mode is user-specified as default.
394 };
395 } // namespace internal
396 
397 // State is passed to a running Benchmark and contains state for the
398 // benchmark to use.
399 class State {
400  public:
401  // Returns true if the benchmark should continue through another iteration.
402  // NOTE: A benchmark may not return from the test until KeepRunning() has
403  // returned false.
404  bool KeepRunning() {
405  if (BENCHMARK_BUILTIN_EXPECT(!started_, false)) {
407  }
408  bool const res = total_iterations_++ < max_iterations;
409  if (BENCHMARK_BUILTIN_EXPECT(!res, false)) {
411  }
412  return res;
413  }
414 
415  // REQUIRES: timer is running and 'SkipWithError(...)' has not been called
416  // by the current thread.
417  // Stop the benchmark timer. If not called, the timer will be
418  // automatically stopped after KeepRunning() returns false for the first time.
419  //
420  // For threaded benchmarks the PauseTiming() function only pauses the timing
421  // for the current thread.
422  //
423  // NOTE: The "real time" measurement is per-thread. If different threads
424  // report different measurements the largest one is reported.
425  //
426  // NOTE: PauseTiming()/ResumeTiming() are relatively
427  // heavyweight, and so their use should generally be avoided
428  // within each benchmark iteration, if possible.
429  void PauseTiming();
430 
431  // REQUIRES: timer is not running and 'SkipWithError(...)' has not been called
432  // by the current thread.
433  // Start the benchmark timer. The timer is NOT running on entrance to the
434  // benchmark function. It begins running after the first call to KeepRunning()
435  //
436  // NOTE: PauseTiming()/ResumeTiming() are relatively
437  // heavyweight, and so their use should generally be avoided
438  // within each benchmark iteration, if possible.
439  void ResumeTiming();
440 
441  // REQUIRES: 'SkipWithError(...)' has not been called previously by the
442  // current thread.
443  // Skip any future iterations of the 'KeepRunning()' loop in the current
444  // thread and report an error with the specified 'msg'. After this call
445  // the user may explicitly 'return' from the benchmark.
446  //
447  // For threaded benchmarks only the current thread stops executing and future
448  // calls to `KeepRunning()` will block until all threads have completed
449  // the `KeepRunning()` loop. If multiple threads report an error only the
450  // first error message is used.
451  //
452  // NOTE: Calling 'SkipWithError(...)' does not cause the benchmark to exit
453  // the current scope immediately. If the function is called from within
454  // the 'KeepRunning()' loop the current iteration will finish. It is the users
455  // responsibility to exit the scope as needed.
456  void SkipWithError(const char* msg);
457 
458  // REQUIRES: called exactly once per iteration of the KeepRunning loop.
459  // Set the manually measured time for this benchmark iteration, which
460  // is used instead of automatically measured time if UseManualTime() was
461  // specified.
462  //
463  // For threaded benchmarks the final value will be set to the largest
464  // reported values.
465  void SetIterationTime(double seconds);
466 
467  // Set the number of bytes processed by the current benchmark
468  // execution. This routine is typically called once at the end of a
469  // throughput oriented benchmark. If this routine is called with a
470  // value > 0, the report is printed in MB/sec instead of nanoseconds
471  // per iteration.
472  //
473  // REQUIRES: a benchmark has exited its KeepRunning loop.
476 
478  size_t bytes_processed() const { return bytes_processed_; }
479 
480  // If this routine is called with complexity_n > 0 and complexity report is
481  // requested for the
482  // family benchmark, then current benchmark will be part of the computation
483  // and complexity_n will
484  // represent the length of N.
486  void SetComplexityN(int complexity_n) { complexity_n_ = complexity_n; }
487 
490 
491  // If this routine is called with items > 0, then an items/s
492  // label is printed on the benchmark report line for the currently
493  // executing benchmark. It is typically called at the end of a processing
494  // benchmark where a processing items/second output is desired.
495  //
496  // REQUIRES: a benchmark has exited its KeepRunning loop.
498  void SetItemsProcessed(size_t items) { items_processed_ = items; }
499 
501  size_t items_processed() const { return items_processed_; }
502 
503  // If this routine is called, the specified label is printed at the
504  // end of the benchmark report line for the currently executing
505  // benchmark. Example:
506  // static void BM_Compress(benchmark::State& state) {
507  // ...
508  // double compress = input_size / output_size;
509  // state.SetLabel(StringPrintf("compress:%.1f%%", 100.0*compression));
510  // }
511  // Produces output that looks like:
512  // BM_Compress 50 50 14115038 compress:27.3%
513  //
514  // REQUIRES: a benchmark has exited its KeepRunning loop.
515  void SetLabel(const char* label);
516 
518  this->SetLabel(str.c_str());
519  }
520 
521  // Range arguments for this run. CHECKs if the argument has been set.
523  int range(std::size_t pos = 0) const {
524  assert(range_.size() > pos);
525  return range_[pos];
526  }
527 
528  BENCHMARK_DEPRECATED_MSG("use 'range(0)' instead")
529  int range_x() const { return range(0); }
530 
531  BENCHMARK_DEPRECATED_MSG("use 'range(1)' instead")
532  int range_y() const { return range(1); }
533 
535  size_t iterations() const { return total_iterations_; }
536 
537  private:
538  bool started_;
539  bool finished_;
541 
542  std::vector<int> range_;
543 
546 
548 
550 
551  public:
552  // Container for user-defined counters.
554  // Index of the executing thread. Values from [0, threads).
555  const int thread_index;
556  // Number of threads concurrently executing the benchmark.
557  const int threads;
558  const size_t max_iterations;
559 
560  // TODO(EricWF) make me private
561  State(size_t max_iters, const std::vector<int>& ranges, int thread_i,
562  int n_threads, internal::ThreadTimer* timer,
563  internal::ThreadManager* manager);
564 
565  private:
566  void StartKeepRunning();
567  void FinishKeepRunning();
571 };
572 
573 namespace internal {
574 
575 typedef void(Function)(State&);
576 
577 // ------------------------------------------------------
578 // Benchmark registration object. The BENCHMARK() macro expands
579 // into an internal::Benchmark* object. Various methods can
580 // be called on this object to change the properties of the benchmark.
581 // Each method returns "this" so that multiple method calls can
582 // chained into one expression.
583 class Benchmark {
584  public:
585  virtual ~Benchmark();
586 
587  // Note: the following methods all return "this" so that multiple
588  // method calls can be chained together in one expression.
589 
590  // Run this benchmark once with "x" as the extra argument passed
591  // to the function.
592  // REQUIRES: The function passed to the constructor must accept an arg1.
593  Benchmark* Arg(int x);
594 
595  // Run this benchmark with the given time unit for the generated output report
596  Benchmark* Unit(TimeUnit unit);
597 
598  // Run this benchmark once for a number of values picked from the
599  // range [start..limit]. (start and limit are always picked.)
600  // REQUIRES: The function passed to the constructor must accept an arg1.
601  Benchmark* Range(int start, int limit);
602 
603  // Run this benchmark once for all values in the range [start..limit] with
604  // specific step
605  // REQUIRES: The function passed to the constructor must accept an arg1.
606  Benchmark* DenseRange(int start, int limit, int step = 1);
607 
608  // Run this benchmark once with "args" as the extra arguments passed
609  // to the function.
610  // REQUIRES: The function passed to the constructor must accept arg1, arg2 ...
611  Benchmark* Args(const std::vector<int>& args);
612 
613  // Equivalent to Args({x, y})
614  // NOTE: This is a legacy C++03 interface provided for compatibility only.
615  // New code should use 'Args'.
616  Benchmark* ArgPair(int x, int y) {
617  std::vector<int> args;
618  args.push_back(x);
619  args.push_back(y);
620  return Args(args);
621  }
622 
623  // Run this benchmark once for a number of values picked from the
624  // ranges [start..limit]. (starts and limits are always picked.)
625  // REQUIRES: The function passed to the constructor must accept arg1, arg2 ...
626  Benchmark* Ranges(const std::vector<std::pair<int, int> >& ranges);
627 
628  // Equivalent to ArgNames({name})
630 
631  // Set the argument names to display in the benchmark name. If not called,
632  // only argument values will be shown.
633  Benchmark* ArgNames(const std::vector<std::string>& names);
634 
635  // Equivalent to Ranges({{lo1, hi1}, {lo2, hi2}}).
636  // NOTE: This is a legacy C++03 interface provided for compatibility only.
637  // New code should use 'Ranges'.
638  Benchmark* RangePair(int lo1, int hi1, int lo2, int hi2) {
639  std::vector<std::pair<int, int> > ranges;
640  ranges.push_back(std::make_pair(lo1, hi1));
641  ranges.push_back(std::make_pair(lo2, hi2));
642  return Ranges(ranges);
643  }
644 
645  // Pass this benchmark object to *func, which can customize
646  // the benchmark by calling various methods like Arg, Args,
647  // Threads, etc.
648  Benchmark* Apply(void (*func)(Benchmark* benchmark));
649 
650  // Set the range multiplier for non-dense range. If not called, the range
651  // multiplier kRangeMultiplier will be used.
652  Benchmark* RangeMultiplier(int multiplier);
653 
654  // Set the minimum amount of time to use when running this benchmark. This
655  // option overrides the `benchmark_min_time` flag.
656  // REQUIRES: `t > 0` and `Iterations` has not been called on this benchmark.
657  Benchmark* MinTime(double t);
658 
659  // Specify the amount of iterations that should be run by this benchmark.
660  // REQUIRES: 'n > 0' and `MinTime` has not been called on this benchmark.
661  //
662  // NOTE: This function should only be used when *exact* iteration control is
663  // needed and never to control or limit how long a benchmark runs, where
664  // `--benchmark_min_time=N` or `MinTime(...)` should be used instead.
665  Benchmark* Iterations(size_t n);
666 
667  // Specify the amount of times to repeat this benchmark. This option overrides
668  // the `benchmark_repetitions` flag.
669  // REQUIRES: `n > 0`
670  Benchmark* Repetitions(int n);
671 
672  // Specify if each repetition of the benchmark should be reported separately
673  // or if only the final statistics should be reported. If the benchmark
674  // is not repeated then the single result is always reported.
675  Benchmark* ReportAggregatesOnly(bool value = true);
676 
677  // If a particular benchmark is I/O bound, runs multiple threads internally or
678  // if for some reason CPU timings are not representative, call this method. If
679  // called, the elapsed time will be used to control how many iterations are
680  // run, and in the printing of items/second or MB/seconds values. If not
681  // called, the cpu time used by the benchmark will be used.
683 
684  // If a benchmark must measure time manually (e.g. if GPU execution time is
685  // being
686  // measured), call this method. If called, each benchmark iteration should
687  // call
688  // SetIterationTime(seconds) to report the measured time, which will be used
689  // to control how many iterations are run, and in the printing of items/second
690  // or MB/second values.
692 
693  // Set the asymptotic computational complexity for the benchmark. If called
694  // the asymptotic computational complexity will be shown on the output.
695  Benchmark* Complexity(BigO complexity = benchmark::oAuto);
696 
697  // Set the asymptotic computational complexity for the benchmark. If called
698  // the asymptotic computational complexity will be shown on the output.
699  Benchmark* Complexity(BigOFunc* complexity);
700 
701  // Support for running multiple copies of the same benchmark concurrently
702  // in multiple threads. This may be useful when measuring the scaling
703  // of some piece of code.
704 
705  // Run one instance of this benchmark concurrently in t threads.
706  Benchmark* Threads(int t);
707 
708  // Pick a set of values T from [min_threads,max_threads].
709  // min_threads and max_threads are always included in T. Run this
710  // benchmark once for each value in T. The benchmark run for a
711  // particular value t consists of t threads running the benchmark
712  // function concurrently. For example, consider:
713  // BENCHMARK(Foo)->ThreadRange(1,16);
714  // This will run the following benchmarks:
715  // Foo in 1 thread
716  // Foo in 2 threads
717  // Foo in 4 threads
718  // Foo in 8 threads
719  // Foo in 16 threads
720  Benchmark* ThreadRange(int min_threads, int max_threads);
721 
722  // For each value n in the range, run this benchmark once using n threads.
723  // min_threads and max_threads are always included in the range.
724  // stride specifies the increment. E.g. DenseThreadRange(1, 8, 3) starts
725  // a benchmark with 1, 4, 7 and 8 threads.
726  Benchmark* DenseThreadRange(int min_threads, int max_threads, int stride = 1);
727 
728  // Equivalent to ThreadRange(NumCPUs(), NumCPUs())
730 
731  virtual void Run(State& state) = 0;
732 
733  // Used inside the benchmark implementation
734  struct Instance;
735 
736  protected:
737  explicit Benchmark(const char* name);
738  Benchmark(Benchmark const&);
739  void SetName(const char* name);
740 
741  int ArgsCnt() const;
742 
743  static void AddRange(std::vector<int>* dst, int lo, int hi, int mult);
744 
745  private:
746  friend class BenchmarkFamilies;
747 
750  std::vector<std::string> arg_names_; // Args for all benchmark runs
751  std::vector<std::vector<int> > args_; // Args for all benchmark runs
754  double min_time_;
755  size_t iterations_;
761  std::vector<int> thread_counts_;
762 
763  Benchmark& operator=(Benchmark const&);
764 };
765 
766 } // namespace internal
767 
768 // Create and register a benchmark with the specified 'name' that invokes
769 // the specified functor 'fn'.
770 //
771 // RETURNS: A pointer to the registered benchmark.
773  internal::Function* fn);
774 
775 #if defined(BENCHMARK_HAS_CXX11)
776 template <class Lambda>
777 internal::Benchmark* RegisterBenchmark(const char* name, Lambda&& fn);
778 #endif
779 
780 // Remove all registered benchmarks. All pointers to previously registered
781 // benchmarks are invalidated.
783 
784 namespace internal {
785 // The class used to hold all Benchmarks created from static function.
786 // (ie those created using the BENCHMARK(...) macros.
787 class FunctionBenchmark : public Benchmark {
788  public:
790  : Benchmark(name), func_(func) {}
791 
792  virtual void Run(State& st);
793 
794  private:
796 };
797 
798 #ifdef BENCHMARK_HAS_CXX11
799 template <class Lambda>
800 class LambdaBenchmark : public Benchmark {
801  public:
802  virtual void Run(State& st) { lambda_(st); }
803 
804  private:
805  template <class OLambda>
806  LambdaBenchmark(const char* name, OLambda&& lam)
807  : Benchmark(name), lambda_(std::forward<OLambda>(lam)) {}
808 
809  LambdaBenchmark(LambdaBenchmark const&) = delete;
810 
811  private:
812  template <class Lam>
813  friend Benchmark* ::benchmark::RegisterBenchmark(const char*, Lam&&);
814 
815  Lambda lambda_;
816 };
817 #endif
818 
819 } // namespace internal
820 
822  internal::Function* fn) {
824  ::new internal::FunctionBenchmark(name, fn));
825 }
826 
827 #ifdef BENCHMARK_HAS_CXX11
828 template <class Lambda>
829 internal::Benchmark* RegisterBenchmark(const char* name, Lambda&& fn) {
830  using BenchType =
833  ::new BenchType(name, std::forward<Lambda>(fn)));
834 }
835 #endif
836 
837 #if defined(BENCHMARK_HAS_CXX11) && \
838  (!defined(BENCHMARK_GCC_VERSION) || BENCHMARK_GCC_VERSION >= 409)
839 template <class Lambda, class... Args>
840 internal::Benchmark* RegisterBenchmark(const char* name, Lambda&& fn,
841  Args&&... args) {
843  name, [=](benchmark::State& st) { fn(st, args...); });
844 }
845 #else
846 #define BENCHMARK_HAS_NO_VARIADIC_REGISTER_BENCHMARK
847 #endif
848 
849 // The base class for all fixture tests.
850 class Fixture : public internal::Benchmark {
851  public:
853 
854  virtual void Run(State& st) {
855  this->SetUp(st);
856  this->BenchmarkCase(st);
857  this->TearDown(st);
858  }
859 
860  // These will be deprecated ...
861  virtual void SetUp(const State&) {}
862  virtual void TearDown(const State&) {}
863  // ... In favor of these.
864  virtual void SetUp(State& st) { SetUp(const_cast<const State&>(st)); }
865  virtual void TearDown(State& st) { TearDown(const_cast<const State&>(st)); }
866 
867  protected:
868  virtual void BenchmarkCase(State&) = 0;
869 };
870 
871 } // namespace benchmark
872 
873 // ------------------------------------------------------
874 // Macro to register benchmarks
875 
876 // Check that __COUNTER__ is defined and that __COUNTER__ increases by 1
877 // every time it is expanded. X + 1 == X + 0 is used in case X is defined to be
878 // empty. If X is empty the expression becomes (+1 == +0).
879 #if defined(__COUNTER__) && (__COUNTER__ + 1 == __COUNTER__ + 0)
880 #define BENCHMARK_PRIVATE_UNIQUE_ID __COUNTER__
881 #else
882 #define BENCHMARK_PRIVATE_UNIQUE_ID __LINE__
883 #endif
884 
885 // Helpers for generating unique variable names
886 #define BENCHMARK_PRIVATE_NAME(n) \
887  BENCHMARK_PRIVATE_CONCAT(_benchmark_, BENCHMARK_PRIVATE_UNIQUE_ID, n)
888 #define BENCHMARK_PRIVATE_CONCAT(a, b, c) BENCHMARK_PRIVATE_CONCAT2(a, b, c)
889 #define BENCHMARK_PRIVATE_CONCAT2(a, b, c) a##b##c
890 
891 #define BENCHMARK_PRIVATE_DECLARE(n) \
892  static ::benchmark::internal::Benchmark* BENCHMARK_PRIVATE_NAME(n) \
893  BENCHMARK_UNUSED
894 
895 #define BENCHMARK(n) \
896  BENCHMARK_PRIVATE_DECLARE(n) = \
897  (::benchmark::internal::RegisterBenchmarkInternal( \
898  new ::benchmark::internal::FunctionBenchmark(#n, n)))
899 
900 // Old-style macros
901 #define BENCHMARK_WITH_ARG(n, a) BENCHMARK(n)->Arg((a))
902 #define BENCHMARK_WITH_ARG2(n, a1, a2) BENCHMARK(n)->Args({(a1), (a2)})
903 #define BENCHMARK_WITH_UNIT(n, t) BENCHMARK(n)->Unit((t))
904 #define BENCHMARK_RANGE(n, lo, hi) BENCHMARK(n)->Range((lo), (hi))
905 #define BENCHMARK_RANGE2(n, l1, h1, l2, h2) \
906  BENCHMARK(n)->RangePair({{(l1), (h1)}, {(l2), (h2)}})
907 
908 #if __cplusplus >= 201103L
909 
910 // Register a benchmark which invokes the function specified by `func`
911 // with the additional arguments specified by `...`.
912 //
913 // For example:
914 //
915 // template <class ...ExtraArgs>`
916 // void BM_takes_args(benchmark::State& state, ExtraArgs&&... extra_args) {
917 // [...]
918 //}
919 // /* Registers a benchmark named "BM_takes_args/int_string_test` */
920 // BENCHMARK_CAPTURE(BM_takes_args, int_string_test, 42, std::string("abc"));
921 #define BENCHMARK_CAPTURE(func, test_case_name, ...) \
922  BENCHMARK_PRIVATE_DECLARE(func) = \
923  (::benchmark::internal::RegisterBenchmarkInternal( \
924  new ::benchmark::internal::FunctionBenchmark( \
925  #func "/" #test_case_name, \
926  [](::benchmark::State& st) { func(st, __VA_ARGS__); })))
927 
928 #endif // __cplusplus >= 11
929 
930 // This will register a benchmark for a templatized function. For example:
931 //
932 // template<int arg>
933 // void BM_Foo(int iters);
934 //
935 // BENCHMARK_TEMPLATE(BM_Foo, 1);
936 //
937 // will register BM_Foo<1> as a benchmark.
938 #define BENCHMARK_TEMPLATE1(n, a) \
939  BENCHMARK_PRIVATE_DECLARE(n) = \
940  (::benchmark::internal::RegisterBenchmarkInternal( \
941  new ::benchmark::internal::FunctionBenchmark(#n "<" #a ">", n<a>)))
942 
943 #define BENCHMARK_TEMPLATE2(n, a, b) \
944  BENCHMARK_PRIVATE_DECLARE(n) = \
945  (::benchmark::internal::RegisterBenchmarkInternal( \
946  new ::benchmark::internal::FunctionBenchmark(#n "<" #a "," #b ">", \
947  n<a, b>)))
948 
949 #if __cplusplus >= 201103L
950 #define BENCHMARK_TEMPLATE(n, ...) \
951  BENCHMARK_PRIVATE_DECLARE(n) = \
952  (::benchmark::internal::RegisterBenchmarkInternal( \
953  new ::benchmark::internal::FunctionBenchmark( \
954  #n "<" #__VA_ARGS__ ">", n<__VA_ARGS__>)))
955 #else
956 #define BENCHMARK_TEMPLATE(n, a) BENCHMARK_TEMPLATE1(n, a)
957 #endif
958 
959 #define BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
960  class BaseClass##_##Method##_Benchmark : public BaseClass { \
961  public: \
962  BaseClass##_##Method##_Benchmark() : BaseClass() { \
963  this->SetName(#BaseClass "/" #Method); \
964  } \
965  \
966  protected: \
967  virtual void BenchmarkCase(::benchmark::State&); \
968  };
969 
970 #define BENCHMARK_DEFINE_F(BaseClass, Method) \
971  BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
972  void BaseClass##_##Method##_Benchmark::BenchmarkCase
973 
974 #define BENCHMARK_REGISTER_F(BaseClass, Method) \
975  BENCHMARK_PRIVATE_REGISTER_F(BaseClass##_##Method##_Benchmark)
976 
977 #define BENCHMARK_PRIVATE_REGISTER_F(TestName) \
978  BENCHMARK_PRIVATE_DECLARE(TestName) = \
979  (::benchmark::internal::RegisterBenchmarkInternal(new TestName()))
980 
981 // This macro will define and register a benchmark within a fixture class.
982 #define BENCHMARK_F(BaseClass, Method) \
983  BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
984  BENCHMARK_REGISTER_F(BaseClass, Method); \
985  void BaseClass##_##Method##_Benchmark::BenchmarkCase
986 
987 // Helper macro to create a main routine in a test that runs the benchmarks
988 #define BENCHMARK_MAIN() \
989  int main(int argc, char** argv) { \
990  ::benchmark::Initialize(&argc, argv); \
991  if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1; \
992  ::benchmark::RunSpecifiedBenchmarks(); \
993  }
994 
995 
996 // ------------------------------------------------------
997 // Benchmark Reporters
998 
999 namespace benchmark {
1000 
1001 // Interface for custom benchmark result printers.
1002 // By default, benchmark reports are printed to stdout. However an application
1003 // can control the destination of the reports by calling
1004 // RunSpecifiedBenchmarks and passing it a custom reporter object.
1005 // The reporter object must implement the following interface.
1007  public:
1008  struct Context {
1010  double mhz_per_cpu;
1012 
1013  // The number of chars in the longest benchmark name.
1015  };
1016 
1017  struct Run {
1019  : error_occurred(false),
1020  iterations(1),
1024  bytes_per_second(0),
1025  items_per_second(0),
1026  max_heapbytes_used(0),
1027  complexity(oNone),
1029  complexity_n(0),
1031  report_rms(false),
1032  counters() {}
1033 
1035  std::string report_label; // Empty if not set by benchmark.
1038 
1039  int64_t iterations;
1043 
1044  // Return a value representing the real time per iteration in the unit
1045  // specified by 'time_unit'.
1046  // NOTE: If 'iterations' is zero the returned value represents the
1047  // accumulated time.
1048  double GetAdjustedRealTime() const;
1049 
1050  // Return a value representing the cpu time per iteration in the unit
1051  // specified by 'time_unit'.
1052  // NOTE: If 'iterations' is zero the returned value represents the
1053  // accumulated time.
1054  double GetAdjustedCPUTime() const;
1055 
1056  // Zero if not set by benchmark.
1059 
1060  // This is set to 0.0 if memory tracing is not enabled.
1062 
1063  // Keep track of arguments to compute asymptotic complexity
1067 
1068  // Inform print function whether the current run is a complexity report
1071 
1073  };
1074 
1075  // Construct a BenchmarkReporter with the output stream set to 'std::cout'
1076  // and the error stream set to 'std::cerr'
1078 
1079  // Called once for every suite of benchmarks run.
1080  // The parameter "context" contains information that the
1081  // reporter may wish to use when generating its report, for example the
1082  // platform under which the benchmarks are running. The benchmark run is
1083  // never started if this function returns false, allowing the reporter
1084  // to skip runs based on the context information.
1085  virtual bool ReportContext(const Context& context) = 0;
1086 
1087  // Called once for each group of benchmark runs, gives information about
1088  // cpu-time and heap memory usage during the benchmark run. If the group
1089  // of runs contained more than two entries then 'report' contains additional
1090  // elements representing the mean and standard deviation of those runs.
1091  // Additionally if this group of runs was the last in a family of benchmarks
1092  // 'reports' contains additional entries representing the asymptotic
1093  // complexity and RMS of that benchmark family.
1094  virtual void ReportRuns(const std::vector<Run>& report) = 0;
1095 
1096  // Called once and only once after ever group of benchmarks is run and
1097  // reported.
1098  virtual void Finalize() {}
1099 
1100  // REQUIRES: The object referenced by 'out' is valid for the lifetime
1101  // of the reporter.
1102  void SetOutputStream(std::ostream* out) {
1103  assert(out);
1104  output_stream_ = out;
1105  }
1106 
1107  // REQUIRES: The object referenced by 'err' is valid for the lifetime
1108  // of the reporter.
1109  void SetErrorStream(std::ostream* err) {
1110  assert(err);
1111  error_stream_ = err;
1112  }
1113 
1114  std::ostream& GetOutputStream() const { return *output_stream_; }
1115 
1116  std::ostream& GetErrorStream() const { return *error_stream_; }
1117 
1118  virtual ~BenchmarkReporter();
1119 
1120  // Write a human readable string to 'out' representing the specified
1121  // 'context'.
1122  // REQUIRES: 'out' is non-null.
1123  static void PrintBasicContext(std::ostream* out, Context const& context);
1124 
1125  private:
1126  std::ostream* output_stream_;
1127  std::ostream* error_stream_;
1128 };
1129 
1130 // Simple reporter that outputs benchmark data to the console. This is the
1131 // default reporter used by RunSpecifiedBenchmarks().
1133 public:
1135  OO_None = 0,
1140  };
1142  : output_options_(opts_), name_field_width_(0),
1144 
1145  virtual bool ReportContext(const Context& context);
1146  virtual void ReportRuns(const std::vector<Run>& reports);
1147 
1148  protected:
1149  virtual void PrintRunData(const Run& report);
1150  virtual void PrintHeader(const Run& report);
1151 
1156 };
1157 
1159  public:
1161  virtual bool ReportContext(const Context& context);
1162  virtual void ReportRuns(const std::vector<Run>& reports);
1163  virtual void Finalize();
1164 
1165  private:
1166  void PrintRunData(const Run& report);
1167 
1169 };
1170 
1172  public:
1174  virtual bool ReportContext(const Context& context);
1175  virtual void ReportRuns(const std::vector<Run>& reports);
1176 
1177  private:
1178  void PrintRunData(const Run& report);
1179 
1181  std::set< std::string > user_counter_names_;
1182 };
1183 
1184 inline const char* GetTimeUnitString(TimeUnit unit) {
1185  switch (unit) {
1186  case kMillisecond:
1187  return "ms";
1188  case kMicrosecond:
1189  return "us";
1190  case kNanosecond:
1191  default:
1192  return "ns";
1193  }
1194 }
1195 
1196 inline double GetTimeUnitMultiplier(TimeUnit unit) {
1197  switch (unit) {
1198  case kMillisecond:
1199  return 1e3;
1200  case kMicrosecond:
1201  return 1e6;
1202  case kNanosecond:
1203  default:
1204  return 1e9;
1205  }
1206 }
1207 
1208 } // namespace benchmark
1209 
1210 #endif // BENCHMARK_BENCHMARK_H_
benchmark::JSONReporter::ReportRuns
virtual void ReportRuns(const std::vector< Run > &reports)
Definition: json_reporter.cc:90
benchmark::BenchmarkReporter::GetErrorStream
std::ostream & GetErrorStream() const
Definition: benchmark.h:1116
benchmark::State::range_x
int range_x() const
Definition: benchmark.h:529
benchmark::internal::FunctionBenchmark::Run
virtual void Run(State &st)
Definition: benchmark_register.cc:459
forward
static int forward(class zmq::socket_base_t *from_, class zmq::socket_base_t *to_, class zmq::socket_base_t *capture_, zmq::msg_t *msg_, stats_socket &recving, stats_socket &sending)
Definition: proxy.cpp:89
benchmark::Counter::kAvgThreads
@ kAvgThreads
Definition: benchmark.h:347
name
GLuint const GLchar * name
Definition: glcorearb.h:3055
benchmark::State::SetLabel
void SetLabel(const char *label)
Definition: benchmark.cc:449
benchmark::State::bytes_processed_
size_t bytes_processed_
Definition: benchmark.h:544
benchmark::BenchmarkReporter::SetErrorStream
void SetErrorStream(std::ostream *err)
Definition: benchmark.h:1109
benchmark::internal::Benchmark::time_unit_
TimeUnit time_unit_
Definition: benchmark.h:752
benchmark::JSONReporter::PrintRunData
void PrintRunData(const Run &report)
Definition: json_reporter.cc:117
benchmark::State::max_iterations
const size_t max_iterations
Definition: benchmark.h:558
benchmark
Definition: benchmark.h:241
benchmark::internal::RM_Unspecified
@ RM_Unspecified
Definition: benchmark.h:391
benchmark::internal::ThreadTimer
Definition: benchmark.cc:167
benchmark::internal::Benchmark::range_multiplier_
int range_multiplier_
Definition: benchmark.h:753
benchmark::internal::Benchmark::~Benchmark
virtual ~Benchmark()
Definition: benchmark_register.cc:241
benchmark::BenchmarkReporter::Run::complexity_lambda
BigOFunc * complexity_lambda
Definition: benchmark.h:1065
benchmark::internal::Benchmark::ThreadRange
Benchmark * ThreadRange(int min_threads, int max_threads)
Definition: benchmark_register.cc:418
benchmark::Fixture::SetUp
virtual void SetUp(const State &)
Definition: benchmark.h:861
benchmark::internal::Benchmark::ArgsCnt
int ArgsCnt() const
Definition: benchmark_register.cc:447
benchmark::CSVReporter
Definition: benchmark.h:1171
benchmark::BenchmarkReporter::BenchmarkReporter
BenchmarkReporter()
Definition: reporter.cc:29
benchmark::BenchmarkReporter::Run::complexity_n
int complexity_n
Definition: benchmark.h:1066
benchmark::BenchmarkReporter::error_stream_
std::ostream * error_stream_
Definition: benchmark.h:1127
benchmark::JSONReporter::first_report_
bool first_report_
Definition: benchmark.h:1168
benchmark::internal::Benchmark::use_real_time_
bool use_real_time_
Definition: benchmark.h:757
benchmark::BenchmarkReporter::~BenchmarkReporter
virtual ~BenchmarkReporter()
Definition: reporter.cc:32
benchmark::Counter::flags
Flags flags
Definition: benchmark.h:353
benchmark::ConsoleReporter::output_options_
OutputOptions output_options_
Definition: benchmark.h:1152
label
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:4316
benchmark::ConsoleReporter::ReportContext
virtual bool ReportContext(const Context &context)
Definition: console_reporter.cc:36
benchmark::ConsoleReporter::OO_ColorTabular
@ OO_ColorTabular
Definition: benchmark.h:1138
benchmark::CSVReporter::ReportContext
virtual bool ReportContext(const Context &context)
Definition: csv_reporter.cc:40
benchmark::Fixture::TearDown
virtual void TearDown(State &st)
Definition: benchmark.h:865
benchmark::internal::Benchmark::complexity_
BigO complexity_
Definition: benchmark.h:759
benchmark::State::manager_
internal::ThreadManager * manager_
Definition: benchmark.h:569
benchmark::internal::Benchmark::Threads
Benchmark * Threads(int t)
Definition: benchmark_register.cc:412
benchmark::Counter::value
double value
Definition: benchmark.h:352
benchmark::BenchmarkReporter::Run::report_rms
bool report_rms
Definition: benchmark.h:1070
benchmark::DoNotOptimize
BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const &value)
Definition: benchmark.h:328
benchmark::ConsoleReporter::name_field_width_
size_t name_field_width_
Definition: benchmark.h:1153
benchmark::State::SetLabel
void BENCHMARK_ALWAYS_INLINE SetLabel(const std::string &str)
Definition: benchmark.h:517
benchmark::State::total_iterations_
size_t total_iterations_
Definition: benchmark.h:540
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
benchmark::internal::Benchmark::Repetitions
Benchmark * Repetitions(int n)
Definition: benchmark_register.cc:376
benchmark::internal::Benchmark::Complexity
Benchmark * Complexity(BigO complexity=benchmark::oAuto)
Definition: benchmark_register.cc:401
benchmark::Fixture::Fixture
Fixture()
Definition: benchmark.h:852
benchmark::internal::Benchmark::RangePair
Benchmark * RangePair(int lo1, int hi1, int lo2, int hi2)
Definition: benchmark.h:638
y
GLint y
Definition: glcorearb.h:2768
benchmark::State::counters
UserCounters counters
Definition: benchmark.h:553
benchmark::RegisterBenchmark
internal::Benchmark * RegisterBenchmark(const char *name, internal::Function *fn)
Definition: benchmark.h:821
benchmark::internal::RegisterBenchmarkInternal
Benchmark * RegisterBenchmarkInternal(Benchmark *)
Definition: benchmark_register.cc:209
benchmark::TimeUnit
TimeUnit
Definition: benchmark.h:369
x
GLint GLenum GLint x
Definition: glcorearb.h:2834
benchmark::internal::Benchmark::Range
Benchmark * Range(int start, int limit)
Definition: benchmark_register.cc:277
benchmark::State::PauseTiming
void PauseTiming()
Definition: benchmark.cc:420
benchmark::BenchmarkReporter::Context::name_field_width
size_t name_field_width
Definition: benchmark.h:1014
benchmark::ConsoleReporter::PrintHeader
virtual void PrintHeader(const Run &report)
Definition: console_reporter.cc:55
benchmark::JSONReporter::Finalize
virtual void Finalize()
Definition: json_reporter.cc:112
benchmark::State::started_
bool started_
Definition: benchmark.h:538
benchmark::internal::Benchmark::ArgNames
Benchmark * ArgNames(const std::vector< std::string > &names)
Definition: benchmark_register.cc:327
benchmark::CSVReporter::CSVReporter
CSVReporter()
Definition: benchmark.h:1173
bytes
uint8 bytes[10]
Definition: coded_stream_unittest.cc:153
benchmark::internal::Benchmark::SetName
void SetName(const char *name)
Definition: benchmark_register.cc:445
benchmark::JSONReporter::ReportContext
virtual bool ReportContext(const Context &context)
Definition: json_reporter.cc:58
benchmark::State::items_processed
BENCHMARK_ALWAYS_INLINE size_t items_processed() const
Definition: benchmark.h:501
benchmark::kMillisecond
@ kMillisecond
Definition: benchmark.h:369
benchmark::internal::Benchmark::UseManualTime
Benchmark * UseManualTime()
Definition: benchmark_register.cc:394
benchmark::Fixture
Definition: benchmark.h:850
benchmark::ConsoleReporter::prev_counters_
UserCounters prev_counters_
Definition: benchmark.h:1154
flags
GLbitfield flags
Definition: glcorearb.h:3585
benchmark::BenchmarkReporter::Run::GetAdjustedCPUTime
double GetAdjustedCPUTime() const
Definition: reporter.cc:62
benchmark::BenchmarkReporter::PrintBasicContext
static void PrintBasicContext(std::ostream *out, Context const &context)
Definition: reporter.cc:34
benchmark::Fixture::TearDown
virtual void TearDown(const State &)
Definition: benchmark.h:862
benchmark::State::bytes_processed
BENCHMARK_ALWAYS_INLINE size_t bytes_processed() const
Definition: benchmark.h:478
benchmark::internal::Benchmark::thread_counts_
std::vector< int > thread_counts_
Definition: benchmark.h:761
benchmark::internal::Benchmark::name_
std::string name_
Definition: benchmark.h:748
benchmark::RunSpecifiedBenchmarks
size_t RunSpecifiedBenchmarks()
Definition: benchmark.cc:571
benchmark::ConsoleReporter::OO_Defaults
@ OO_Defaults
Definition: benchmark.h:1139
benchmark::ConsoleReporter::printed_header_
bool printed_header_
Definition: benchmark.h:1155
benchmark::Fixture::BenchmarkCase
virtual void BenchmarkCase(State &)=0
benchmark::internal::Benchmark::Args
Benchmark * Args(const std::vector< int > &args)
Definition: benchmark_register.cc:343
benchmark::internal::Benchmark::operator=
Benchmark & operator=(Benchmark const &)
benchmark::internal::Benchmark::RangeMultiplier
Benchmark * RangeMultiplier(int multiplier)
Definition: benchmark_register.cc:354
benchmark::ConsoleReporter::PrintRunData
virtual void PrintRunData(const Run &report)
Definition: console_reporter.cc:101
benchmark::State::range_y
int range_y() const
Definition: benchmark.h:532
benchmark::Counter::kAvgThreadsRate
@ kAvgThreadsRate
Definition: benchmark.h:349
benchmark::internal::Benchmark::Unit
Benchmark * Unit(TimeUnit unit)
Definition: benchmark_register.cc:272
benchmark::ConsoleReporter::OutputOptions
OutputOptions
Definition: benchmark.h:1134
benchmark::BenchmarkReporter::Run::error_message
std::string error_message
Definition: benchmark.h:1037
benchmark::oNSquared
@ oNSquared
Definition: benchmark.h:375
benchmark::internal::RM_ReportAggregatesOnly
@ RM_ReportAggregatesOnly
Definition: benchmark.h:393
stride
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:3141
benchmark::internal::Benchmark::AddRange
static void AddRange(std::vector< int > *dst, int lo, int hi, int mult)
Definition: benchmark_register.cc:243
benchmark::BenchmarkReporter::Run::report_label
std::string report_label
Definition: benchmark.h:1035
benchmark::BenchmarkReporter::Run::cpu_accumulated_time
double cpu_accumulated_time
Definition: benchmark.h:1042
benchmark::internal::Benchmark::ThreadPerCpu
Benchmark * ThreadPerCpu()
Definition: benchmark_register.cc:439
benchmark::State::SkipWithError
void SkipWithError(const char *msg)
Definition: benchmark.cc:431
benchmark::State::timer_
internal::ThreadTimer * timer_
Definition: benchmark.h:568
start
GLuint start
Definition: glcorearb.h:2858
benchmark::internal::FunctionBenchmark
Definition: benchmark.h:787
benchmark::State::iterations
BENCHMARK_ALWAYS_INLINE size_t iterations() const
Definition: benchmark.h:535
benchmark::oLambda
@ oLambda
Definition: benchmark.h:375
benchmark::internal::Benchmark::DenseThreadRange
Benchmark * DenseThreadRange(int min_threads, int max_threads, int stride=1)
Definition: benchmark_register.cc:426
update_failure_list.str
str
Definition: update_failure_list.py:41
benchmark::ConsoleReporter::OO_Color
@ OO_Color
Definition: benchmark.h:1136
benchmark::ConsoleReporter::ReportRuns
virtual void ReportRuns(const std::vector< Run > &reports)
Definition: console_reporter.cc:72
benchmark::BenchmarkReporter::Run::benchmark_name
std::string benchmark_name
Definition: benchmark.h:1034
benchmark::internal::Benchmark::report_mode_
ReportMode report_mode_
Definition: benchmark.h:749
benchmark::o1
@ o1
Definition: benchmark.h:375
benchmark::ClearRegisteredBenchmarks
void ClearRegisteredBenchmarks()
Definition: benchmark_register.cc:463
benchmark::internal::Benchmark::Run
virtual void Run(State &state)=0
err
static UPB_NORETURN void err(tarjan *t)
Definition: ruby/ext/google/protobuf_c/upb.c:5856
benchmark::internal::Benchmark::args_
std::vector< std::vector< int > > args_
Definition: benchmark.h:751
benchmark::State::SetIterationTime
void SetIterationTime(double seconds)
Definition: benchmark.cc:445
benchmark::Initialize
void Initialize(int *argc, char **argv)
Definition: benchmark.cc:703
benchmark::internal::Function
void() Function(State &)
Definition: benchmark.h:575
benchmark::internal::InitializeStreams
int InitializeStreams()
Definition: benchmark.cc:696
benchmark::GetTimeUnitString
const char * GetTimeUnitString(TimeUnit unit)
Definition: benchmark.h:1184
benchmark::Counter::kDefaults
@ kDefaults
Definition: benchmark.h:341
benchmark::internal::Benchmark::Apply
Benchmark * Apply(void(*func)(Benchmark *benchmark))
Definition: benchmark_register.cc:349
benchmark::Counter::kIsRate
@ kIsRate
Definition: benchmark.h:344
benchmark::ConsoleReporter
Definition: benchmark.h:1132
benchmark::State::complexity_n_
int complexity_n_
Definition: benchmark.h:547
benchmark::Counter
Definition: benchmark.h:337
benchmark::BenchmarkReporter::Run
Definition: benchmark.h:1017
benchmark::ReportUnrecognizedArguments
bool ReportUnrecognizedArguments(int argc, char **argv)
Definition: benchmark.cc:708
benchmark::internal::FunctionBenchmark::func_
Function * func_
Definition: benchmark.h:795
benchmark::internal::Benchmark::ArgPair
Benchmark * ArgPair(int x, int y)
Definition: benchmark.h:616
benchmark::State::KeepRunning
bool KeepRunning()
Definition: benchmark.h:404
benchmark::BenchmarkReporter::Run::items_per_second
double items_per_second
Definition: benchmark.h:1058
benchmark::Fixture::SetUp
virtual void SetUp(State &st)
Definition: benchmark.h:864
benchmark::internal::Benchmark
Definition: benchmark.h:583
benchmark::BenchmarkReporter::ReportContext
virtual bool ReportContext(const Context &context)=0
benchmark::State::complexity_length_n
BENCHMARK_ALWAYS_INLINE int complexity_length_n()
Definition: benchmark.h:489
benchmark::oAuto
@ oAuto
Definition: benchmark.h:375
benchmark::internal::Benchmark::MinTime
Benchmark * MinTime(double t)
Definition: benchmark_register.cc:361
benchmark::internal::Benchmark::use_manual_time_
bool use_manual_time_
Definition: benchmark.h:758
void
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
n
GLdouble n
Definition: glcorearb.h:4153
benchmark::State::FinishKeepRunning
void FinishKeepRunning()
Definition: benchmark.cc:461
benchmark::BenchmarkReporter::output_stream_
std::ostream * output_stream_
Definition: benchmark.h:1126
benchmark::Counter::Counter
BENCHMARK_ALWAYS_INLINE Counter(double v=0., Flags f=kDefaults)
Definition: benchmark.h:356
benchmark::State::finished_
bool finished_
Definition: benchmark.h:539
benchmark::internal::Benchmark::min_time_
double min_time_
Definition: benchmark.h:754
benchmark::BenchmarkReporter::ReportRuns
virtual void ReportRuns(const std::vector< Run > &report)=0
benchmark::internal::ReportMode
ReportMode
Definition: benchmark.h:385
benchmark::internal::RM_Default
@ RM_Default
Definition: benchmark.h:392
benchmark::oNone
@ oNone
Definition: benchmark.h:375
benchmark::internal::Benchmark::Benchmark
Benchmark(const char *name)
Definition: benchmark_register.cc:228
type
GLenum type
Definition: glcorearb.h:2695
benchmark::BenchmarkReporter::Run::bytes_per_second
double bytes_per_second
Definition: benchmark.h:1057
benchmark::kNanosecond
@ kNanosecond
Definition: benchmark.h:369
benchmark::BenchmarkReporter::SetOutputStream
void SetOutputStream(std::ostream *out)
Definition: benchmark.h:1102
benchmark::BenchmarkReporter::Context::mhz_per_cpu
double mhz_per_cpu
Definition: benchmark.h:1010
BENCHMARK_DEPRECATED_MSG
#define BENCHMARK_DEPRECATED_MSG(msg)
Definition: benchmark.h:232
benchmark::internal::BenchmarkFamilies
Definition: benchmark_register.cc:66
benchmark::BenchmarkReporter
Definition: benchmark.h:1006
benchmark::State::range
BENCHMARK_ALWAYS_INLINE int range(std::size_t pos=0) const
Definition: benchmark.h:523
benchmark::BenchmarkReporter::Run::complexity
BigO complexity
Definition: benchmark.h:1064
v
const GLdouble * v
Definition: glcorearb.h:3106
benchmark::oNCubed
@ oNCubed
Definition: benchmark.h:375
googletest-break-on-failure-unittest.Run
def Run(command)
Definition: googletest-break-on-failure-unittest.py:76
BENCHMARK_BUILTIN_EXPECT
#define BENCHMARK_BUILTIN_EXPECT(x, y)
Definition: benchmark.h:231
Args
Args({7, 6, 3})
benchmark::BenchmarkReporter::Run::real_accumulated_time
double real_accumulated_time
Definition: benchmark.h:1041
benchmark::State
Definition: benchmark.h:399
benchmark::BenchmarkReporter::Run::time_unit
TimeUnit time_unit
Definition: benchmark.h:1040
std
benchmark::State::items_processed_
size_t items_processed_
Definition: benchmark.h:545
benchmark::JSONReporter::JSONReporter
JSONReporter()
Definition: benchmark.h:1160
benchmark::State::error_occurred_
bool error_occurred_
Definition: benchmark.h:549
benchmark::internal::ThreadManager
Definition: benchmark.cc:116
func
GLenum func
Definition: glcorearb.h:3052
benchmark::BenchmarkReporter::Finalize
virtual void Finalize()
Definition: benchmark.h:1098
benchmark::internal::Benchmark::ReportAggregatesOnly
Benchmark * ReportAggregatesOnly(bool value=true)
Definition: benchmark_register.cc:382
BENCHMARK_UNUSED
#define BENCHMARK_UNUSED
Definition: benchmark.h:218
benchmark::State::SetItemsProcessed
BENCHMARK_ALWAYS_INLINE void SetItemsProcessed(size_t items)
Definition: benchmark.h:498
benchmark::BigO
BigO
Definition: benchmark.h:375
dst
GLenum GLenum dst
Definition: glcorearb.h:3364
benchmark::State::StartKeepRunning
void StartKeepRunning()
Definition: benchmark.cc:454
benchmark::ConsoleReporter::OO_Tabular
@ OO_Tabular
Definition: benchmark.h:1137
benchmark::BenchmarkReporter::Run::GetAdjustedRealTime
double GetAdjustedRealTime() const
Definition: reporter.cc:56
benchmark::internal::Benchmark::DenseRange
Benchmark * DenseRange(int start, int limit, int step=1)
Definition: benchmark_register.cc:333
benchmark::ConsoleReporter::ConsoleReporter
ConsoleReporter(OutputOptions opts_=OO_Defaults)
Definition: benchmark.h:1141
benchmark::State::threads
const int threads
Definition: benchmark.h:557
benchmark::BenchmarkReporter::Run::error_occurred
bool error_occurred
Definition: benchmark.h:1036
benchmark::internal::Benchmark::iterations_
size_t iterations_
Definition: benchmark.h:755
benchmark::State::range_
std::vector< int > range_
Definition: benchmark.h:542
benchmark::BenchmarkReporter::Run::Run
Run()
Definition: benchmark.h:1018
benchmark::CSVReporter::user_counter_names_
std::set< std::string > user_counter_names_
Definition: benchmark.h:1181
true
#define true
Definition: cJSON.c:65
internal
Definition: any.pb.h:40
benchmark::internal::Benchmark::Iterations
Benchmark * Iterations(size_t n)
Definition: benchmark_register.cc:369
benchmark::UserCounters
std::map< std::string, Counter > UserCounters
Definition: benchmark.h:364
benchmark::BigOFunc
double() BigOFunc(int)
Definition: benchmark.h:379
benchmark::internal::Benchmark::ArgName
Benchmark * ArgName(const std::string &name)
Definition: benchmark_register.cc:321
benchmark::State::thread_index
const int thread_index
Definition: benchmark.h:555
f
GLfloat f
Definition: glcorearb.h:3964
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
benchmark::GetTimeUnitMultiplier
double GetTimeUnitMultiplier(TimeUnit unit)
Definition: benchmark.h:1196
benchmark::internal::Benchmark::repetitions_
int repetitions_
Definition: benchmark.h:756
benchmark::internal::Benchmark::UseRealTime
Benchmark * UseRealTime()
Definition: benchmark_register.cc:387
benchmark::State::State
State(size_t max_iters, const std::vector< int > &ranges, int thread_i, int n_threads, internal::ThreadTimer *timer, internal::ThreadManager *manager)
Definition: benchmark.cc:399
benchmark::State::SetComplexityN
BENCHMARK_ALWAYS_INLINE void SetComplexityN(int complexity_n)
Definition: benchmark.h:486
benchmark::Counter::Flags
Flags
Definition: benchmark.h:340
BENCHMARK_ALWAYS_INLINE
#define BENCHMARK_ALWAYS_INLINE
Definition: benchmark.h:219
benchmark::BenchmarkReporter::Context::num_cpus
int num_cpus
Definition: benchmark.h:1009
benchmark::internal::FunctionBenchmark::FunctionBenchmark
FunctionBenchmark(const char *name, Function *func)
Definition: benchmark.h:789
benchmark::internal::Benchmark::complexity_lambda_
BigOFunc * complexity_lambda_
Definition: benchmark.h:760
false
#define false
Definition: cJSON.c:70
benchmark::internal::stream_init_anchor
static BENCHMARK_UNUSED int stream_init_anchor
Definition: benchmark.h:287
benchmark::internal::Benchmark::Ranges
Benchmark * Ranges(const std::vector< std::pair< int, int > > &ranges)
Definition: benchmark_register.cc:288
benchmark::BenchmarkReporter::Context
Definition: benchmark.h:1008
benchmark::BenchmarkReporter::GetOutputStream
std::ostream & GetOutputStream() const
Definition: benchmark.h:1114
benchmark::BenchmarkReporter::Run::report_big_o
bool report_big_o
Definition: benchmark.h:1069
benchmark::State::ResumeTiming
void ResumeTiming()
Definition: benchmark.cc:426
benchmark::oLogN
@ oLogN
Definition: benchmark.h:375
benchmark::oN
@ oN
Definition: benchmark.h:375
benchmark::oNLogN
@ oNLogN
Definition: benchmark.h:375
benchmark::BenchmarkReporter::Run::counters
UserCounters counters
Definition: benchmark.h:1072
benchmark::State::BENCHMARK_DISALLOW_COPY_AND_ASSIGN
BENCHMARK_DISALLOW_COPY_AND_ASSIGN(State)
benchmark::kMicrosecond
@ kMicrosecond
Definition: benchmark.h:369
benchmark::CSVReporter::PrintRunData
void PrintRunData(const Run &report)
Definition: csv_reporter.cc:86
benchmark::Fixture::Run
virtual void Run(State &st)
Definition: benchmark.h:854
benchmark::CSVReporter::printed_header_
bool printed_header_
Definition: benchmark.h:1180
benchmark::State::SetBytesProcessed
BENCHMARK_ALWAYS_INLINE void SetBytesProcessed(size_t bytes)
Definition: benchmark.h:475
benchmark::BenchmarkReporter::Context::cpu_scaling_enabled
bool cpu_scaling_enabled
Definition: benchmark.h:1011
benchmark::internal::Benchmark::Arg
Benchmark * Arg(int x)
Definition: benchmark_register.cc:266
benchmark::BenchmarkReporter::Run::iterations
int64_t iterations
Definition: benchmark.h:1039
benchmark::ConsoleReporter::OO_None
@ OO_None
Definition: benchmark.h:1135
benchmarks.python.py_benchmark.args
args
Definition: py_benchmark.py:24
benchmark::internal::UseCharPointer
void UseCharPointer(char const volatile *)
Definition: benchmark.cc:104
benchmark::internal::Benchmark::arg_names_
std::vector< std::string > arg_names_
Definition: benchmark.h:750
benchmark::JSONReporter
Definition: benchmark.h:1158
benchmark::BenchmarkReporter::Run::max_heapbytes_used
double max_heapbytes_used
Definition: benchmark.h:1061
benchmark::CSVReporter::ReportRuns
virtual void ReportRuns(const std::vector< Run > &reports)
Definition: csv_reporter.cc:45


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:48