Home | History | Annotate | Download | only in benchmark

Lines Matching full:benchmark

20 static void BM_StringCreation(benchmark::State& state) {
25 // Register the function as a benchmark
26 BENCHMARK(BM_StringCreation);
28 // Define another benchmark
29 static void BM_StringCopy(benchmark::State& state) {
34 BENCHMARK(BM_StringCopy);
43 benchmark::Initialize(&argc, argv);
44 benchmark::RunSpecifiedBenchmarks();
54 static void BM_memcpy(benchmark::State& state) {
63 BENCHMARK(BM_memcpy)->Arg(8)->Arg(64)->Arg(512)->Arg(1<<10)->Arg(8<<10);
69 BENCHMARK(BM_memcpy)->Range(8, 8<<10);
74 static void BM_SetInsert(benchmark::State& state) {
84 BENCHMARK(BM_SetInsert)
98 BENCHMARK(BM_SetInsert)->Ranges({{1<<10, 8<<10}, {128, 512}});
105 static void CustomArguments(benchmark::internal::Benchmark* b) {
110 BENCHMARK(BM_SetInsert)->Apply(CustomArguments);
115 template <class Q> int BM_Sequential(benchmark::State& state) {
130 Use `Benchmark::MinTime(double t)` to set the minimum time used to run the
131 benchmark. This option overrides the `benchmark_min_time` flag.
133 void BM_test(benchmark::State& state) {
136 BENCHMARK(BM_test)->MinTime(2.0); // Run for at least 2 seconds.
143 static void BM_MultiThreaded(benchmark::State& state) {
154 BENCHMARK(BM_MultiThreaded)->Threads(4);
157 If a benchmark runs a few milliseconds it may be hard to visually compare the
161 BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
242 namespace benchmark {
253 // of each matching benchmark. Otherwise run each matching benchmark and
269 // benchmark is reported at the end of the benchmark report line. (It is
270 // computed by running the benchmark once with a single iteration and a memory
276 class Benchmark;
282 // Take ownership of the pointer and register the benchmark. Return the
283 // registered benchmark.
284 Benchmark* RegisterBenchmarkInternal(Benchmark*);
346 // by the duration of the benchmark.
370 // TimeUnit is passed to a benchmark in order to specify the order of magnitude
374 // BigO is passed to a benchmark in order to specify the asymptotic
376 // complexity for the benchmark. In case oAuto is selected, complexity will be
380 // BigOFunc is passed to a benchmark in order to specify the asymptotic
381 // computational complexity for the benchmark.
384 // StatisticsFunc is passed to a benchmark in order to compute some descriptive
412 // State is passed to a running Benchmark and contains state for the
413 // benchmark to use.
419 // Returns iterators used to run each iteration of a benchmark using a
422 // REQUIRES: The benchmark has not started running yet. Neither begin nor end
429 // Returns true if the benchmark should continue through another iteration.
430 // NOTE: A benchmark may not return from the test until KeepRunning() has
445 // Stop the benchmark timer. If not called, the timer will be
446 // automatically stopped after the last iteration of the benchmark loop.
456 // within each benchmark iteration, if possible.
461 // Start the benchmark timer. The timer is NOT running on entrance to the
462 // benchmark function. It begins running after control flow enters the
463 // benchmark loop.
467 // within each benchmark iteration, if possible.
472 // Report the benchmark as resulting in an error with the specified 'msg'.
473 // After this call the user may explicitly 'return' from the benchmark.
475 // If the ranged-for style of benchmark loop is used, the user must explicitly
485 // NOTE: Calling 'SkipWithError(...)' does not cause the benchmark to exit
492 // Set the manually measured time for this benchmark iteration, which
500 // Set the number of bytes processed by the current benchmark
502 // throughput oriented benchmark. If this routine is called with a
506 // REQUIRES: a benchmark has exited its benchmarking loop.
515 // family benchmark, then current benchmark will be part of the computation
525 // label is printed on the benchmark report line for the currently
526 // executing benchmark. It is typically called at the end of a processing
527 // benchmark where a processing items/second output is desired.
529 // REQUIRES: a benchmark has exited its benchmarking loop.
537 // end of the benchmark report line for the currently executing
538 // benchmark. Example:
539 // static void BM_Compress(benchmark::State& state) {
547 // REQUIRES: a benchmark has exited its benchmarking loop.
589 // Number of threads concurrently executing the benchmark.
658 // Benchmark registration object. The BENCHMARK() macro expands
659 // into an internal::Benchmark* object. Various methods can
660 // be called on this object to change the properties of the benchmark.
663 class Benchmark {
665 virtual ~Benchmark();
670 // Run this benchmark once with "x" as the extra argument passed
673 Benchmark* Arg(int x);
675 // Run this benchmark with the given time unit for the generated output report
676 Benchmark* Unit(TimeUnit unit);
678 // Run this benchmark once for a number of values picked from the
681 Benchmark* Range(int start, int limit);
683 // Run this benchmark once for all values in the range [start..limit] with
686 Benchmark* DenseRange(int start, int limit, int step = 1);
688 // Run this benchmark once with "args" as the extra arguments passed
691 Benchmark* Args(const std::vector<int>& args);
696 Benchmark* ArgPair(int x, int y) {
703 // Run this benchmark once for a number of values picked from the
706 Benchmark* Ranges(const std::vector<std::pair<int, int> >& ranges);
709 Benchmark* ArgName(const std::string& name);
711 // Set the argument names to display in the benchmark name. If not called,
713 Benchmark* ArgNames(const std::vector<std::string>& names);
718 Benchmark* RangePair(int lo1, int hi1, int lo2, int hi2) {
725 // Pass this benchmark object to *func, which can customize
726 // the benchmark by calling various methods like Arg, Args,
728 Benchmark* Apply(void (*func)(Benchmark* benchmark));
732 Benchmark* RangeMultiplier(int multiplier);
734 // Set the minimum amount of time to use when running this benchmark. This
736 // REQUIRES: `t > 0` and `Iterations` has not been called on this benchmark.
737 Benchmark* MinTime(double t);
739 // Specify the amount of iterations that should be run by this benchmark.
740 // REQUIRES: 'n > 0' and `MinTime` has not been called on this benchmark.
743 // needed and never to control or limit how long a benchmark runs, where
745 Benchmark* Iterations(size_t n);
747 // Specify the amount of times to repeat this benchmark. This option overrides
750 Benchmark* Repetitions(int n);
752 // Specify if each repetition of the benchmark should be reported separately
753 // or if only the final statistics should be reported. If the benchmark
755 Benchmark* ReportAggregatesOnly(bool value = true);
757 // If a particular benchmark is I/O bound, runs multiple threads internally or
761 // called, the cpu time used by the benchmark will be used.
762 Benchmark* UseRealTime();
764 // If a benchmark must measure time manually (e.g. if GPU execution time is
766 // measured), call this method. If called, each benchmark iteration should
771 Benchmark* UseManualTime();
773 // Set the asymptotic computational complexity for the benchmark. If called
775 Benchmark* Complexity(BigO complexity = benchmark::oAuto);
777 // Set the asymptotic computational complexity for the benchmark. If called
779 Benchmark* Complexity(BigOFunc* complexity);
781 // Add this statistics to be computed over all the values of benchmark run
782 Benchmark* ComputeStatistics(std::string name, StatisticsFunc* statistics);
784 // Support for running multiple copies of the same benchmark concurrently
788 // Run one instance of this benchmark concurrently in t threads.
789 Benchmark* Threads(int t);
793 // benchmark once for each value in T. The benchmark run for a
794 // particular value t consists of t threads running the benchmark
796 // BENCHMARK(Foo)->ThreadRange(1,16);
803 Benchmark* ThreadRange(int min_threads, int max_threads);
805 // For each value n in the range, run this benchmark once using n threads.
808 // a benchmark with 1, 4, 7 and 8 threads.
809 Benchmark* DenseThreadRange(int min_threads, int max_threads, int stride = 1);
812 Benchmark* ThreadPerCpu();
816 // Used inside the benchmark implementation
820 explicit Benchmark(const char* name);
821 Benchmark(Benchmark const&);
833 std::vector<std::string> arg_names_; // Args for all benchmark runs
834 std::vector<std::vector<int> > args_; // Args for all benchmark runs
847 Benchmark& operator=(Benchmark const&);
852 // Create and register a benchmark with the specified 'name' that invokes
855 // RETURNS: A pointer to the registered benchmark.
856 internal::Benchmark* RegisterBenchmark(const char* name,
861 internal::Benchmark* RegisterBenchmark(const char* name, Lambda&& fn);
870 // (ie those created using the BENCHMARK(...) macros.
871 class FunctionBenchmark : public Benchmark {
874 : Benchmark(name), func_(func) {}
884 class LambdaBenchmark : public Benchmark {
891 : Benchmark(name), lambda_(std::forward<OLambda>(lam)) {}
897 friend Benchmark* ::benchmark::RegisterBenchmark(const char*, Lam&&);
905 inline internal::Benchmark* RegisterBenchmark(const char* name,
913 internal::Benchmark* RegisterBenchmark(const char* name, Lambda&& fn) {
924 internal::Benchmark* RegisterBenchmark(const char* name, Lambda&& fn,
926 return benchmark::RegisterBenchmark(
927 name, [=](benchmark::State& st) { fn(st, args...); });
934 class Fixture : public internal::Benchmark {
936 Fixture() : internal::Benchmark("") {}
955 } // namespace benchmark
976 static ::benchmark::internal::Benchmark* BENCHMARK_PRIVATE_NAME(n) \
979 #define BENCHMARK(n) \
981 (::benchmark::internal::RegisterBenchmarkInternal( \
982 new ::benchmark::internal::FunctionBenchmark(#n, n)))
985 #define BENCHMARK_WITH_ARG(n, a) BENCHMARK(n)->Arg((a))
986 #define BENCHMARK_WITH_ARG2(n, a1, a2) BENCHMARK(n)->Args({(a1), (a2)})
987 #define BENCHMARK_WITH_UNIT(n, t) BENCHMARK(n)->Unit((t))
988 #define BENCHMARK_RANGE(n, lo, hi) BENCHMARK(n)->Range((lo), (hi))
990 BENCHMARK(n)->RangePair({{(l1), (h1)}, {(l2), (h2)}})
994 // Register a benchmark which invokes the function specified by `func`
1000 // void BM_takes_args(benchmark::State& state, ExtraArgs&&... extra_args) {
1003 // /* Registers a benchmark named "BM_takes_args/int_string_test` */
1007 (::benchmark::internal::RegisterBenchmarkInternal( \
1008 new ::benchmark::internal::FunctionBenchmark( \
1010 [](::benchmark::State& st) { func(st, __VA_ARGS__); })))
1014 // This will register a benchmark for a templatized function. For example:
1021 // will register BM_Foo<1> as a benchmark.
1024 (::benchmark::internal::RegisterBenchmarkInternal( \
1025 new ::benchmark::internal::FunctionBenchmark(#n "<" #a ">", n<a>)))
1029 (::benchmark::internal::RegisterBenchmarkInternal( \
1030 new ::benchmark::internal::FunctionBenchmark(#n "<" #a "," #b ">", \
1036 (::benchmark::internal::RegisterBenchmarkInternal( \
1037 new ::benchmark::internal::FunctionBenchmark( \
1051 virtual void BenchmarkCase(::benchmark::State&); \
1062 virtual void BenchmarkCase(::benchmark::State&); \
1073 virtual void BenchmarkCase(::benchmark::State&); \
1085 virtual void BenchmarkCase(::benchmark::State&); \
1116 (::benchmark::internal::RegisterBenchmarkInternal(new TestName()))
1118 // This macro will define and register a benchmark within a fixture class.
1146 ::benchmark::Initialize(&argc, argv); \
1147 if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1; \
1148 ::benchmark::RunSpecifiedBenchmarks(); \
1154 // Benchmark Reporters
1156 namespace benchmark {
1178 // Interface for custom benchmark result printers.
1179 // By default, benchmark reports are printed to stdout. However an application
1187 // The number of chars in the longest benchmark name.
1211 std::string report_label; // Empty if not set by benchmark.
1232 // Zero if not set by benchmark.
1261 // platform under which the benchmarks are running. The benchmark run is
1266 // Called once for each group of benchmark runs, gives information about
1267 // cpu-time and heap memory usage during the benchmark run. If the group
1272 // complexity and RMS of that benchmark family.
1309 // Simple reporter that outputs benchmark data to the console. This is the
1387 } // namespace benchmark