-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathUnitTest.cpp
More file actions
144 lines (122 loc) · 2.59 KB
/
Copy pathUnitTest.cpp
File metadata and controls
144 lines (122 loc) · 2.59 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "Common.h"
#include "PageCache.h"
#include "ConcurrentAlloc.h"
void TestSize()
{
/*cout << SizeClass::Index(10) << endl;
cout << SizeClass::Index(16) << endl;
cout << SizeClass::Index(128) << endl;
cout << SizeClass::Index(129) << endl;
cout << SizeClass::Index(128 + 17) << endl;
cout << SizeClass::Index(1025) << endl;
cout << SizeClass::Index(1024 + 129) << endl;
cout << SizeClass::Index(8*1024+1) << endl;
cout << SizeClass::Index(8*1024 + 1024) << endl;
*/
cout << SizeClass::Roundup(10) << endl;
cout << SizeClass::Roundup(1025) << endl;
cout << SizeClass::Roundup(1024 * 8 + 1) << endl;
cout << SizeClass::NumMovePage(16) << endl;
cout << SizeClass::NumMovePage(1024) << endl;
cout << SizeClass::NumMovePage(1024 * 8) << endl;
cout << SizeClass::NumMovePage(1024 * 64) << endl;
}
void Alloc(size_t n)
{
size_t begin1 = clock();
std::vector<void*> v;
for (size_t i = 0; i < n; ++i)
{
v.push_back(ConcurrentAlloc(10));
}
//v.push_back(ConcurrentAlloc(10));
for (size_t i = 0; i < n; ++i)
{
ConcurrentFree(v[i]);
cout << v[i] << endl;
}
v.clear();
size_t end1 = clock();
size_t begin2 = clock();
cout << endl << endl;
for (size_t i = 0; i < n; ++i)
{
v.push_back(ConcurrentAlloc(10));
}
for (size_t i = 0; i < n; ++i)
{
ConcurrentFree(v[i]);
cout << v[i] << endl;
}
v.clear();
size_t end2 = clock();
cout << end1 - begin1 << endl;
cout << end2 - begin2 << endl;
}
void TestThreadCache()
{
std::thread t1(Alloc, 1000000);
//std::thread t2(Alloc, 5);
//std::thread t3(Alloc, 5);
//std::thread t4(Alloc, 5);
t1.join();
//t2.join();
//t3.join();
//t4.join();
}
void TestCentralCache()
{
std::vector<void*> v;
for (size_t i = 0; i < 8; ++i)
{
v.push_back(ConcurrentAlloc(10));
}
for (size_t i = 0; i < 8; ++i)
{
//ConcurrentFree(v[i], 10);
cout << v[i] << endl;
}
}
void TestPageCache()
{
PageCache::GetInstence()->NewSpan(2);
}
void TestConcurrentAllocFree()
{
size_t n = 2;
std::vector<void*> v;
for (size_t i = 0; i < n; ++i)
{
void* ptr = ConcurrentAlloc(99999);
v.push_back(ptr);
//printf("obj:%d->%p\n", i, ptr);
//if (i == 2999999)
//{
// printf("obj:%d->%p\n", i, ptr);
//}
}
for (size_t i = 0; i < n; ++i)
{
ConcurrentFree(v[i]);
}
cout << "hehe" << endl;
}
void AllocBig()
{
void* ptr1 = ConcurrentAlloc(65 << PAGE_SHIFT);
void* ptr2 = ConcurrentAlloc(129 << PAGE_SHIFT);
ConcurrentFree(ptr1);
ConcurrentFree(ptr2);
}
//int main()
//{
// //TestSize();
// //TestThreadCache();
// //TestCentralCache();
// //TestPageCache();
// TestConcurrentAllocFree();
//
// //AllocBig();
// system("pause");
// return 0;
//}