-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdemo.cpp
35 lines (27 loc) · 874 Bytes
/
demo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include "InstrumentorTimer.h"
#include "InstrumentorMacro.h"
namespace Benchmark {
int Fibonacci(int x) {
std::string name = std::string("Fibonacci ") + std::to_string(x);
PROFILE_SCOPE(name.c_str());
std::this_thread::sleep_for(std::chrono::microseconds(1)); // Compensate statistical temporal precision problem
if (x < 3) return 1;
int part1 = Fibonacci(x - 1);
int part2 = Fibonacci(x - 2);
return part1 + part2;
}
void RunBenchmarks() {
PROFILE_FUNCTION();
std::cout << "Running Benchmarks..." << std::endl;
std::thread t1([]() { Fibonacci(9); });
std::thread t2([]() { Fibonacci(10); });
t1.join();
t2.join();
}
}
int main() {
Instrumentor::BeginSession("Benchmark");
Benchmark::RunBenchmarks();
return 0;
}