-
Notifications
You must be signed in to change notification settings - Fork 1
/
MTPool.cpp
57 lines (55 loc) · 1.15 KB
/
MTPool.cpp
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
#include "MTPool.h"
#include <vector>
#include "LifeCircleLogger.h"
using namespace std;
object_pool<CCSprite> spritePool;
static void testPoolEfficiency(){
const int test_time = 1;
vector<int> ops;
int tot=0;
for(int i=0;i<test_time;i++){
int op=0;
if(tot){
if(rand()%2==0){
op=1;
}
}
if(op) tot--;
else tot++;
ops.push_back(op);
}
{
LifeCircleLogger logger("use system new");
CCArray *tmp = CCArray::array();
for(int i=0;i<test_time;i++){
if(ops[i]){
tmp->removeLastObject();
}else{
CCSprite *sp = CCSprite::node();
tmp->addObject(sp);
}
}
}{
LifeCircleLogger logger("use MTPool");
CCArray *tmp = CCArray::array();
for(int i=0;i<test_time;i++){
if(ops[i]){
tmp->removeLastObject();
}else{
CCSprite *sp = MTPoolManager::sharedManager()->getObject(sp);
tmp->addObject(sp);
}
}
}{
LifeCircleLogger logger("use boost Pool");
CCArray *tmp = CCArray::array();
for(int i=0;i<test_time;i++){
if(ops[i]){
tmp->removeLastObject();
}else{
CCSprite *sp =spritePool.construct();
tmp->addObject(sp);
}
}
}
}