-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze_benchmark.cpp
More file actions
68 lines (54 loc) · 1.57 KB
/
analyze_benchmark.cpp
File metadata and controls
68 lines (54 loc) · 1.57 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <vector>
#include <thread>
#include <allocator.h>
using namespace WW;
constexpr size_type THREAD = 2; // 线程数
constexpr size_type ROUND = 1000; // 轮数
constexpr size_type TIMES = 1000; // 单次测试操作次数
/**
* @brief 测试结构
*/
template <size_type Size>
class TestCase
{
public:
char padding[Size];
};
int main()
{
std::vector<std::thread> pool_threads;
pool_threads.reserve(THREAD);
// 512bytes
pool_threads.emplace_back([]() {
allocator<TestCase<512>> alloc;
for (size_type j = 0; j < ROUND; ++j) {
std::vector<TestCase<512> *> ptrs;
ptrs.reserve(TIMES);
for (size_type k = 0; k < TIMES; ++k) {
TestCase<512> * ptr = alloc.allocate(1);
ptrs.emplace_back(ptr);
}
for (size_type k = 0; k < TIMES; ++k) {
alloc.deallocate(ptrs[k], 1);
}
}
});
// 1024bytes
pool_threads.emplace_back([]() {
allocator<TestCase<1024>> alloc;
for (size_type j = 0; j < ROUND; ++j) {
std::vector<TestCase<1024> *> ptrs;
ptrs.reserve(TIMES);
for (size_type k = 0; k < TIMES; ++k) {
TestCase<1024> * ptr = alloc.allocate(1);
ptrs.emplace_back(ptr);
}
for (size_type k = 0; k < TIMES; ++k) {
alloc.deallocate(ptrs[k], 1);
}
}
});
for (std::thread & thread : pool_threads) {
thread.join();
}
}