-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
69 lines (58 loc) · 1.6 KB
/
test.cpp
File metadata and controls
69 lines (58 loc) · 1.6 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
69
#include"./datastructure/DataStructure.h"
#include<chrono>
#include<iostream>
#include<vector>
#define ELEM 50000
struct AA
{
int a ;
char b ;
long long c ;
long long d ;
long long e ;
AA(int aa , char bb , long long cc ,long long dd ): a(aa) , b(bb) ,c(cc) ,d(dd)
{
return ;
}
AA()
{
}
};
int main()
{
StackAlloc<AA, MemoryPool<AA>> Stackpool;
auto start = std::chrono::high_resolution_clock::now();
for (int i = 0; i < ELEM; i++)
{
AA aa(i, 'a', i, i);
Stackpool.push(aa);
}
for (int i = 0; i < ELEM; i++)
{
Stackpool.pop();
}
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> duration = end - start;
std::cout << "MemoryPool time: " << duration.count() << " ms" << std::endl;
std::cout<<"------------------------------------\n";
StackAlloc<AA, std::allocator<AA>> Stackallocator;
auto start2 = std::chrono::high_resolution_clock::now();
for (int i = 0; i < ELEM/4; i++)
{
AA aa(i, 'b', i, i);
Stackallocator.push(aa);
Stackallocator.push(aa);
Stackallocator.push(aa);
Stackallocator.push(aa);
}
for (int i = 0; i < ELEM/4; i++)
{
Stackallocator.pop();
Stackallocator.pop();
Stackallocator.pop();
Stackallocator.pop();
}
auto end2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> duration2 = end2 - start2;
std::cout << "std::allocator time: " << duration2.count() << " ms" << std::endl;
}