10 #define CPPBENCHMARK_H
23 class BenchmarkRegistrator
26 explicit BenchmarkRegistrator(
const std::function<std::shared_ptr<BenchmarkBase>()>& builder)
36 #define BENCHMARK_INTERNAL_UNIQUE_NAME_LINE2(name, line) name##line
37 #define BENCHMARK_INTERNAL_UNIQUE_NAME_LINE(name, line) BENCHMARK_INTERNAL_UNIQUE_NAME_LINE2(name, line)
38 #define BENCHMARK_INTERNAL_UNIQUE_NAME(name) BENCHMARK_INTERNAL_UNIQUE_NAME_LINE(name, __LINE__)
46 #define BENCHMARK_MAIN()\
47 int main(int argc, char** argv)\
49 CppBenchmark::LauncherConsole::GetInstance().Initialize(argc, argv);\
50 CppBenchmark::LauncherConsole::GetInstance().Execute();\
51 CppBenchmark::LauncherConsole::GetInstance().Report();\
68 #define BENCHMARK(...)\
69 namespace CppBenchmark {\
70 class BENCHMARK_INTERNAL_UNIQUE_NAME(__benchmark__) : public Benchmark\
73 using Benchmark::Benchmark;\
75 void Run(Context& context) override;\
77 Internals::BenchmarkRegistrator BENCHMARK_INTERNAL_UNIQUE_NAME(benchmark_registrator)([]() { return std::make_shared<BENCHMARK_INTERNAL_UNIQUE_NAME(__benchmark__)>(__VA_ARGS__); });\
79 void CppBenchmark::BENCHMARK_INTERNAL_UNIQUE_NAME(__benchmark__)::Run(CppBenchmark::Context& context)
128 #define BENCHMARK_FIXTURE(fixture, ...)\
129 namespace CppBenchmark {\
130 class BENCHMARK_INTERNAL_UNIQUE_NAME(__benchmark__) : public Benchmark, public fixture\
133 using Benchmark::Benchmark;\
135 void Run(Context& context) override;\
137 Internals::BenchmarkRegistrator BENCHMARK_INTERNAL_UNIQUE_NAME(benchmark_registrator)([]() { return std::make_shared<BENCHMARK_INTERNAL_UNIQUE_NAME(__benchmark__)>(__VA_ARGS__); });\
139 void CppBenchmark::BENCHMARK_INTERNAL_UNIQUE_NAME(__benchmark__)::Run(Context& context)
156 #define BENCHMARK_THREADS(...)\
157 namespace CppBenchmark {\
158 class BENCHMARK_INTERNAL_UNIQUE_NAME(__benchmark__) : public BenchmarkThreads\
161 using BenchmarkThreads::BenchmarkThreads;\
163 void RunThread(ContextThreads& context) override;\
165 Internals::BenchmarkRegistrator BENCHMARK_INTERNAL_UNIQUE_NAME(benchmark_registrator)([]() { return std::make_shared<BENCHMARK_INTERNAL_UNIQUE_NAME(__benchmark__)>(__VA_ARGS__); });\
167 void CppBenchmark::BENCHMARK_INTERNAL_UNIQUE_NAME(__benchmark__)::RunThread(CppBenchmark::ContextThreads& context)
224 #define BENCHMARK_THREADS_FIXTURE(fixture, ...)\
225 namespace CppBenchmark {\
226 class BENCHMARK_INTERNAL_UNIQUE_NAME(__benchmark__) : public BenchmarkThreads, public fixture\
229 using BenchmarkThreads::BenchmarkThreads;\
231 void RunThread(ContextThreads& context) override;\
233 Internals::BenchmarkRegistrator BENCHMARK_INTERNAL_UNIQUE_NAME(benchmark_registrator)([]() { return std::make_shared<BENCHMARK_INTERNAL_UNIQUE_NAME(__benchmark__)>(__VA_ARGS__); });\
235 void CppBenchmark::BENCHMARK_INTERNAL_UNIQUE_NAME(__benchmark__)::RunThread(ContextThreads& context)
258 #define BENCHMARK_CLASS(type, ...)\
259 namespace CppBenchmark { Internals::BenchmarkRegistrator BENCHMARK_INTERNAL_UNIQUE_NAME(benchmark_registrator)([]() { return std::make_shared<type>(__VA_ARGS__); }); }
277 #define BENCHCODE_SCOPE(name) CppBenchmark::Executor::ScopeBenchmark(name);
294 #define BENCHCODE_START(name) CppBenchmark::Executor::StartBenchmark(name);
311 #define BENCHCODE_STOP(name) CppBenchmark::Executor::StopBenchmark(name);
331 #define BENCHCODE_REPORT()\
333 CppBenchmark::ReporterConsole BENCHMARK_INTERNAL_UNIQUE_NAME(reporter);\
334 CppBenchmark::Executor::Report(BENCHMARK_INTERNAL_UNIQUE_NAME(reporter));\
349 #define BENCHCODE_REPORT_STR(value)\
351 std::ostringstream BENCHMARK_INTERNAL_UNIQUE_NAME(output);\
352 CppBenchmark::ReporterConsole BENCHMARK_INTERNAL_UNIQUE_NAME(reporter)(BENCHMARK_INTERNAL_UNIQUE_NAME(output));\
353 CppBenchmark::Executor::Report(BENCHMARK_INTERNAL_UNIQUE_NAME(reporter));\
354 value = BENCHMARK_INTERNAL_UNIQUE_NAME(output).str();\
369 #define BENCHCODE_REPORT_CSV(value)\
371 std::ostringstream BENCHMARK_INTERNAL_UNIQUE_NAME(output);\
372 CppBenchmark::ReporterCSV BENCHMARK_INTERNAL_UNIQUE_NAME(reporter)(BENCHMARK_INTERNAL_UNIQUE_NAME(output));\
373 CppBenchmark::Executor::Report(BENCHMARK_INTERNAL_UNIQUE_NAME(reporter));\
374 value = BENCHMARK_INTERNAL_UNIQUE_NAME(output).str();\
389 #define BENCHCODE_REPORT_JSON(value)\
391 std::ostringstream BENCHMARK_INTERNAL_UNIQUE_NAME(output);\
392 CppBenchmark::ReporterJSON BENCHMARK_INTERNAL_UNIQUE_NAME(reporter)(BENCHMARK_INTERNAL_UNIQUE_NAME(output));\
393 CppBenchmark::Executor::Report(BENCHMARK_INTERNAL_UNIQUE_NAME(reporter));\
394 value = BENCHMARK_INTERNAL_UNIQUE_NAME(output).str();\
static LauncherConsole & GetInstance()
Get singleton instance.
void AddBenchmarkBuilder(const std::function< std::shared_ptr< BenchmarkBase >()> &builder)
Add the given benchmark builder function to the benchmark builders collection.
Dynamic benchmarks executor definition.
Console launcher definition.
C++ Benchmark project definitions.
Console reporter definition.
Comma-separated values (CSV) reporter definition.
JSON reporter definition.