-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.c
125 lines (102 loc) · 2.16 KB
/
main.c
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
#include <stdio.h>
#include <time.h>
#include "mpool.h"
#include "m_vector.h"
#include "thpool.h"
int bsz = 8;
int times = 100000;
int runtimes = 100;
void test_pool()
{
MemPool *pool = pool_create(128,10);
char *cp;
int i = 0;
for ( ; i < 15; ++i )
{
char *c = (char*)m_malloc(pool);
sprintf(c,"%d\tThis Is My Pool\n",i+1);
printf(c);
}
cp = m_malloc(pool);
m_free(pool,&cp);
m_free(pool,&cp);
cp = m_malloc(pool);
pool_release(pool);
}
void * f1(void *arg)
{
printf("==================Func 1\n");
return NULL;
}
void * f2(void* arg)
{
printf("==================Func 2\n");
return NULL;
}
void test_malloc()
{
clock_t start, end;
int i , j ;
start = clock();
for( j = 0 ;j < runtimes; ++j)
for ( i = 0 ; i < times; ++i)
{
void *f = malloc(bsz);
free(f);
}
end = clock();
fprintf(stdout,"malloc Time Ellapsed:%d\n",end-start);
}
//void test_boost()
//{
// boost::pool<> bpool(bsz);
// clock_t start, end;
// int i , j;
// start = clock();
// for( j = 0 ;j < runtimes; ++j)
// for ( i = 0 ; i < times; ++i)
// {
// void *f = bpool.malloc();
// bpool.free(f,bsz);
// }
// end = clock();
// fprintf(stdout,"Boost Pool Time Ellapsed:%dms\n",end-start);
//}
void test_mempool()
{
MemPool *block = pool_create(bsz,1);
clock_t start, end;
int i , j ;
start = clock();
for( j = 0 ;j < runtimes; ++j)
for ( i = 0 ; i < times; ++i)
{
void *f = m_malloc(block);
m_free(block,&f);
}
end = clock();
fprintf(stdout,"Block Pool Time Ellapsed:%d\n",end-start);
pool_release(block);
}
//void test_threadpool()
//{
// thPool *pool = thpool_create(3);
// Task t1 = {f1,NULL}, t2 = {f2,NULL};
// add_Task(pool,&t2);
// add_Task(pool,&t2);
// add_Task(pool,&t1);
// add_Task(pool,&t1);
// add_Task(pool,&t1);
// add_Task(pool,&t2);
// Sleep(3000);
// thpool_release(pool);
//}
int main(void)
{
// test_boost();
test_pool();
test_mempool();
test_malloc();
// test_threadpool();
return 0;
}