#include <chrono>
#include <thread>
#include <vector>
const int THREADS = 8;
void init()
{
std::this_thread::sleep_for(std::chrono::seconds(2));
}
void calculate()
{
for (int i = 0; i < 5; ++i)
{
auto phase1 = benchmark->StartPhase("Calculate.1");
std::this_thread::sleep_for(std::chrono::milliseconds(100));
phase1->StopPhase();
}
auto phase2 = benchmark->StartPhase("Calculate.2");
{
auto phase21 = benchmark->StartPhase("Calculate.2.1");
std::this_thread::sleep_for(std::chrono::milliseconds(200));
phase21->StopPhase();
auto phase22 = benchmark->StartPhase("Calculate.2.2");
std::this_thread::sleep_for(std::chrono::milliseconds(300));
phase22->StopPhase();
}
phase2->StopPhase();
for (int i = 0; i < 3; ++i)
{
auto phase3 = benchmark->StartPhase("Calculate.3");
std::this_thread::sleep_for(std::chrono::milliseconds(400));
phase3->StopPhase();
}
}
void cleanup()
{
std::this_thread::sleep_for(std::chrono::seconds(1));
}
int main(int argc, char** argv)
{
init();
std::vector<std::thread> threads;
for (int i = 0; i < THREADS; ++i)
threads.emplace_back(calculate);
for (auto& thread : threads)
thread.join();
cleanup();
return 0;
}
CppBenchmark definitions.
#define BENCHCODE_STOP(name)
Dynamic benchmark stop macro.
#define BENCHCODE_SCOPE(name)
Dynamic benchmark scope register macro.
#define BENCHCODE_REPORT()
Dynamic benchmarks report to console macro.
#define BENCHCODE_START(name)
Dynamic benchmark start macro.