-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
107 lines (84 loc) · 2.12 KB
/
main.cpp
File metadata and controls
107 lines (84 loc) · 2.12 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
#include <iostream>
#include <ctime>
#include <stdexcept>
//#define ALLOC_POOL_MAX_DELETE_SIZE 1024
//#define ALLOC_POOL_EXCEEDING_DELETE_BEHAVIOUR ALLOC_POOL_FREE
//#define ALLOC_POOL_EXCEEDING_DELETE_BEHAVIOUR ALLOC_POOL_THROW
#include "AllocatorPool.h"
class Dummy : public std::string
{
ALLOC_POOL_IMPLEMENT(Dummy)
};
class DummyNoPool : public std::string
{
};
void doBench(void)
{
std::size_t loopCount = 1024 * 1024;
clock_t begin_time;
for (int i = 0; i < loopCount; i++); // simple setting the bench hot as the first loops seems to be slower
begin_time = std::clock();
for (int i = 0; i < loopCount; i++)
{
Dummy * d;
d = new Dummy();
d->append("Test");
delete d;
Dummy * d1;
d1 = new Dummy();
d1->append("Test");
Dummy * d2;
d2 = new Dummy();
d2->append("Test");
delete d2;
delete d1;
}
double pool_time = double(std::clock() - begin_time) / CLOCKS_PER_SEC;
begin_time = std::clock();
for (int i = 0; i < loopCount; i++)
{
DummyNoPool * d;
d = new DummyNoPool();
d->append("Test");
delete d;
DummyNoPool * d1;
d1 = new DummyNoPool();
d1->append("Test");
DummyNoPool * d2;
d2 = new DummyNoPool();
d2->append("Test");
delete d2;
delete d1;
}
double no_pool_time = double(std::clock() - begin_time) / CLOCKS_PER_SEC;
std::cout << "Pool : " << pool_time << std::endl
<< "No pool : " << no_pool_time << std::endl;
}
void testExceedingDeletes(void)
{
try
{
Dummy * tab[ALLOC_POOL_MAX_DELETE_SIZE + 1];
for (int i = 0; i < ALLOC_POOL_MAX_DELETE_SIZE + 1; i++)
{
tab[i] = new Dummy();
}
for (int i = 0; i < ALLOC_POOL_MAX_DELETE_SIZE + 1; i++)
{
delete tab[i];
}
}
catch (std::length_error le)
{
std::cout << "Succesfully throwed exception std::length_error : " << le.what() << std::endl;
}
}
int main(void)
{
Dummy d; // not interaction with the pool. May need to test this.
doBench();
doBench();
doBench();
testExceedingDeletes();
return 0;
}