My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

const unsigned int s_LoopCount = 5000 * 1000;
const unsigned int s_MemSize = 100;
const unsigned int s_CoreCount = 32;
HANDLE s_heap = NULL;

struct PerfInfo
{
bool globalHeap;
DWORD tickCount;
};

DWORD WINAPI ThreadProc(LPVOID param)
{
PerfInfo * info = (PerfInfo*)param;
DWORD flag = 0;

HANDLE heap = NULL;
if (info->globalHeap)
{
heap = s_heap;
flag = 0;
}
else
{
heap = HeapCreate(0, 0, 0);
ULONG ul = 0;
HeapSetInformation(heap, HeapCompatibilityInformation, &ul, sizeof(ul));
flag = 0;
}

std::vector<char*> vBufs;
vBufs.reserve(s_LoopCount);
vBufs.resize(s_LoopCount);

DWORD dwBegin = GetTickCount();
for (unsigned int i = 0; i < s_LoopCount; ++i)
{
char* p = (char*)HeapAlloc(heap, flag, s_MemSize);
vBufs[i] = p;
}

for (unsigned int i = 0; i < s_LoopCount; ++i)
{
HeapFree(heap, flag, (void*)vBufs[i]);
}

DWORD dwEnd = GetTickCount();

info->tickCount = dwEnd - dwBegin;

if (!info->globalHeap)
{
HeapDestroy(heap);
}

return 0;
}

DWORD ParaDynamicMem(unsigned int coreCount, bool gHeap)
{
HANDLE arraThread[s_CoreCount];
PerfInfo info[s_CoreCount];
for (unsigned int i = 0; i < coreCount; ++i)
{
info[i].globalHeap = gHeap;
info[i].tickCount = 0;
arraThread[i] = CreateThread(NULL,
0,
ThreadProc,
(void*)(info + i),
0,
NULL);
}

WaitForMultipleObjects(coreCount, arraThread, TRUE, INFINITE);

DWORD tickCount = 0;
for (unsigned int i = 0; i < coreCount; ++i)
{
tickCount += info[i].tickCount;
}

tickCount = (DWORD)((tickCount + 0.0) / coreCount);

return tickCount;
}

int main(int argc, char** argv)
{
s_heap = HeapCreate(0, 0, 0);

unsigned int n = argv[1][0] - '0';
bool g = (argv[2][0] == '1');
DWORD time = 0;

time = ParaDynamicMem(n, g);
printf("%I32u core time:%I32u, use global heap? %s.\n", n, time, g ? "true" : "false");

return 0;
}

Change log

r89 by changshuliu on Jul 9, 2011   Diff
    add memory performance analyzer into
tools folder

Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 2428 bytes, 105 lines
Powered by Google Project Hosting