-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread.cpp
More file actions
36 lines (27 loc) · 743 Bytes
/
thread.cpp
File metadata and controls
36 lines (27 loc) · 743 Bytes
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
36
#include <nanobench.h>
#include <thread>
#include <iostream>
#include <vector>
#include <unistd.h>
using namespace std;
long global = 0;
void counter() {
}
int main() {
const int SIZE = 10000;
ankerl::nanobench::Bench().minEpochIterations(SIZE).run("create process fork()", [&] {
if (fork() == 0){
exit(0);
}
});
ankerl::nanobench::Bench().minEpochIterations(SIZE).run("create and run thread", [&] {
thread t(counter);
t.join();
ankerl::nanobench::doNotOptimizeAway(t);
});
ankerl::nanobench::Bench().minEpochIterations(SIZE).run("create thread", [&] {
thread t(counter);
t.detach();
ankerl::nanobench::doNotOptimizeAway(t);
});
}