Home | History | Annotate | Download | only in benchmark

Lines Matching refs:benchmark

6 static void BM_StringCreation(benchmark::State& state) {
11 // Register the function as a benchmark
12 BENCHMARK(BM_StringCreation);
14 // Define another benchmark
15 static void BM_StringCopy(benchmark::State& state) {
20 BENCHMARK(BM_StringCopy);
29 benchmark::Initialize(&argc, argv);
30 benchmark::RunSpecifiedBenchmarks();
40 static void BM_memcpy(benchmark::State& state) {
49 BENCHMARK(BM_memcpy)->Arg(8)->Arg(64)->Arg(512)->Arg(1<<10)->Arg(8<<10);
55 BENCHMARK(BM_memcpy)->Range(8, 8<<10);
60 static void BM_SetInsert(benchmark::State& state) {
69 BENCHMARK(BM_SetInsert)
83 BENCHMARK(BM_SetInsert)->Ranges({{1<<10, 8<<10}, {1, 512}});
90 static void CustomArguments(benchmark::internal::Benchmark* b) {
95 BENCHMARK(BM_SetInsert)->Apply(CustomArguments);
100 template <class Q> int BM_Sequential(benchmark::State& state) {
115 Use `Benchmark::MinTime(double t)` to set the minimum time used to run the
116 benchmark. This option overrides the `benchmark_min_time` flag.
118 void BM_test(benchmark::State& state) {
121 BENCHMARK(BM_test)->MinTime(2.0); // Run for at least 2 seconds.
128 static void BM_MultiThreaded(benchmark::State& state) {
139 BENCHMARK(BM_MultiThreaded)->Threads(4);
142 If a benchmark runs a few milliseconds it may be hard to visually compare the
146 BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
166 namespace benchmark {
173 // of each matching benchmark. Otherwise run each matching benchmark and
189 // benchmark is reported at the end of the benchmark report line. (It is
190 // computed by running the benchmark once with a single iteration and a memory
196 class Benchmark;
215 // Take ownership of the pointer and register the benchmark. Return the
216 // registered benchmark.
217 Benchmark* RegisterBenchmarkInternal(Benchmark*);
247 // TimeUnit is passed to a benchmark in order to specify the order of magnitude
251 // BigO is passed to a benchmark in order to specify the asymptotic
253 // complexity for the benchmark. In case oAuto is selected, complexity will be
257 // BigOFunc is passed to a benchmark in order to specify the asymptotic
258 // computational complexity for the benchmark.
276 // State is passed to a running Benchmark and contains state for the
277 // benchmark to use.
280 // Returns true if the benchmark should continue through another iteration.
281 // NOTE: A benchmark may not return from the test until KeepRunning() has
296 // Stop the benchmark timer. If not called, the timer will be
307 // within each benchmark iteration, if possible.
312 // Start the benchmark timer. The timer is NOT running on entrance to the
313 // benchmark function. It begins running after the first call to KeepRunning()
317 // within each benchmark iteration, if possible.
324 // the user may explicitly 'return' from the benchmark.
331 // NOTE: Calling 'SkipWithError(...)' does not cause the benchmark to exit
338 // Set the manually measured time for this benchmark iteration, which
346 // Set the number of bytes processed by the current benchmark
348 // throughput oriented benchmark. If this routine is called with a
352 // REQUIRES: a benchmark has exited its KeepRunning loop.
361 // family benchmark, then current benchmark will be part of the computation
371 // label is printed on the benchmark report line for the currently
372 // executing benchmark. It is typically called at the end of a processing
373 // benchmark where a processing items/second output is desired.
375 // REQUIRES: a benchmark has exited its KeepRunning loop.
383 // end of the benchmark report line for the currently executing
384 // benchmark. Example:
385 // static void BM_Compress(benchmark::State& state) {
393 // REQUIRES: a benchmark has exited its KeepRunning loop.
439 // Number of threads concurrently executing the benchmark.
461 // Benchmark registration object. The BENCHMARK() macro expands
462 // into an internal::Benchmark* object. Various methods can
463 // be called on this object to change the properties of the benchmark.
466 class Benchmark {
468 virtual ~Benchmark();
473 // Run this benchmark once with "x" as the extra argument passed
476 Benchmark* Arg(int x);
478 // Run this benchmark with the given time unit for the generated output report
479 Benchmark* Unit(TimeUnit unit);
481 // Run this benchmark once for a number of values picked from the
484 Benchmark* Range(int start, int limit);
486 // Run this benchmark once for all values in the range [start..limit] with
489 Benchmark* DenseRange(int start, int limit, int step = 1);
491 // Run this benchmark once with "args" as the extra arguments passed
494 Benchmark* Args(const std::vector<int>& args);
499 Benchmark* ArgPair(int x, int y) {
506 // Run this benchmark once for a number of values picked from the
509 Benchmark* Ranges(const std::vector<std::pair<int, int> >& ranges);
512 Benchmark* ArgName(const std::string& name);
514 // Set the argument names to display in the benchmark name. If not called,
516 Benchmark* ArgNames(const std::vector<std::string>& names);
521 Benchmark* RangePair(int lo1, int hi1, int lo2, int hi2) {
528 // Pass this benchmark object to *func, which can customize
529 // the benchmark by calling various methods like Arg, Args,
531 Benchmark* Apply(void (*func)(Benchmark* benchmark));
535 Benchmark* RangeMultiplier(int multiplier);
537 // Set the minimum amount of time to use when running this benchmark. This
540 Benchmark* MinTime(double t);
542 // Specify the amount of times to repeat this benchmark. This option overrides
545 Benchmark* Repetitions(int n);
547 // Specify if each repetition of the benchmark should be reported separately
548 // or if only the final statistics should be reported. If the benchmark
550 Benchmark* ReportAggregatesOnly(bool v = true);
552 // If a particular benchmark is I/O bound, runs multiple threads internally or
556 // called, the cpu time used by the benchmark will be used.
557 Benchmark* UseRealTime();
559 // If a benchmark must measure time manually (e.g. if GPU execution time is
561 // measured), call this method. If called, each benchmark iteration should
566 Benchmark* UseManualTime();
568 // Set the asymptotic computational complexity for the benchmark. If called
570 Benchmark* Complexity(BigO complexity = benchmark::oAuto);
572 // Set the asymptotic computational complexity for the benchmark. If called
574 Benchmark* Complexity(BigOFunc* complexity);
576 // Support for running multiple copies of the same benchmark concurrently
580 // Run one instance of this benchmark concurrently in t threads.
581 Benchmark* Threads(int t);
585 // benchmark once for each value in T. The benchmark run for a
586 // particular value t consists of t threads running the benchmark
588 // BENCHMARK(Foo)->ThreadRange(1,16);
595 Benchmark* ThreadRange(int min_threads, int max_threads);
597 // For each value n in the range, run this benchmark once using n threads.
600 // a benchmark with 1, 4, 7 and 8 threads.
601 Benchmark* DenseThreadRange(int min_threads, int max_threads, int stride = 1);
604 Benchmark* ThreadPerCpu();
608 // Used inside the benchmark implementation
612 explicit Benchmark(const char* name);
613 Benchmark(Benchmark const&);
625 std::vector<std::string> arg_names_; // Args for all benchmark runs
626 std::vector<std::vector<int> > args_; // Args for all benchmark runs
637 Benchmark& operator=(Benchmark const&);
642 // Create and register a benchmark with the specified 'name' that invokes
645 // RETURNS: A pointer to the registered benchmark.
646 internal::Benchmark* RegisterBenchmark(const char* name,
651 internal::Benchmark* RegisterBenchmark(const char* name, Lambda&& fn);
656 // (ie those created using the BENCHMARK(...) macros.
657 class FunctionBenchmark : public Benchmark {
660 : Benchmark(name), func_(func) {}
670 class LambdaBenchmark : public Benchmark {
677 : Benchmark(name), lambda_(std::forward<OLambda>(lam)) {}
683 friend Benchmark* ::benchmark::RegisterBenchmark(const char*, Lam&&);
691 inline internal::Benchmark* RegisterBenchmark(const char* name,
699 internal::Benchmark* RegisterBenchmark(const char* name, Lambda&& fn) {
710 internal::Benchmark* RegisterBenchmark(const char* name, Lambda&& fn,
712 return benchmark::RegisterBenchmark(
713 name, [=](benchmark::State& st) { fn(st, args...); });
720 class Fixture : public internal::Benchmark {
722 Fixture() : internal::Benchmark("") {}
741 } // end namespace benchmark
762 static ::benchmark::internal::Benchmark* BENCHMARK_PRIVATE_NAME(n) \
765 #define BENCHMARK(n) \
767 (::benchmark::internal::RegisterBenchmarkInternal( \
768 new ::benchmark::internal::FunctionBenchmark(#n, n)))
771 #define BENCHMARK_WITH_ARG(n, a) BENCHMARK(n)->Arg((a))
772 #define BENCHMARK_WITH_ARG2(n, a1, a2) BENCHMARK(n)->Args({(a1), (a2)})
773 #define BENCHMARK_WITH_UNIT(n, t) BENCHMARK(n)->Unit((t))
774 #define BENCHMARK_RANGE(n, lo, hi) BENCHMARK(n)->Range((lo), (hi))
776 BENCHMARK(n)->RangePair({{(l1), (h1)}, {(l2), (h2)}})
780 // Register a benchmark which invokes the function specified by `func`
786 // void BM_takes_args(benchmark::State& state, ExtraArgs&&... extra_args) {
789 // /* Registers a benchmark named "BM_takes_args/int_string_test` */
793 (::benchmark::internal::RegisterBenchmarkInternal( \
794 new ::benchmark::internal::FunctionBenchmark( \
796 [](::benchmark::State& st) { func(st, __VA_ARGS__); })))
800 // This will register a benchmark for a templatized function. For example:
807 // will register BM_Foo<1> as a benchmark.
810 (::benchmark::internal::RegisterBenchmarkInternal( \
811 new ::benchmark::internal::FunctionBenchmark(#n "<" #a ">", n<a>)))
815 (::benchmark::internal::RegisterBenchmarkInternal( \
816 new ::benchmark::internal::FunctionBenchmark(#n "<" #a "," #b ">", \
822 (::benchmark::internal::RegisterBenchmarkInternal( \
823 new ::benchmark::internal::FunctionBenchmark( \
837 virtual void BenchmarkCase(::benchmark::State&); \
849 (::benchmark::internal::RegisterBenchmarkInternal(new TestName()))
851 // This macro will define and register a benchmark within a fixture class.
860 ::benchmark::Initialize(&argc, argv); \
861 ::benchmark::RunSpecifiedBenchmarks(); \