-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
55 lines (33 loc) · 849 Bytes
/
Copy pathMain.cpp
File metadata and controls
55 lines (33 loc) · 849 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <vector>
#include <thread>
#include "./Lapse.h"
constexpr unsigned int nTest = 0x1000000;
struct Test {
~Test(){}
Test():mp(ma){}
char* Func(){ return mp++; }
char ma[nTest];
char* mp;
};
thread_local Test v;
Test& get_v(){ return v; }
void test()
{
std::vector<std::thread> at(std::thread::hardware_concurrency());
{ //
Lapse l;
for (auto& t : at) t = std::thread([=]{ for (unsigned int n = nTest; n; --n) v.Func(); });
for (auto& t : at) t.join();
}
{ //
Lapse l;
for (auto& t : at) t = std::thread([=]{ decltype(auto) rv = get_v(); for (unsigned int n = nTest; n; --n) rv.Func(); });
for (auto& t : at) t.join();
}
}
int main(int argc, char* argv[])
{
test();
test();
return 0;
}