My favorites
▼
|
Sign in
code4cs
Code Repository for Changshu Liu
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
Tools
/
MemPerfor
/
CachePerf.cpp
r138
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
#include <Windows.h>
#include <stdio.h>
#include <vector>
//
// Conclusion: false sharing will cause unrelated data to be synced among processor cores
// in cache line unit.
//
static volatile __int64 g_arraNum[8 * 64] = {0};
DWORD WINAPI ParaInc(void* p)
{
volatile __int64 arraNum = 0;
DWORD dwBegin = GetTickCount();
__int32 threadID = (__int32)p;
for (int i = 0; i < 1000 * 1000 * 10; ++i)
{
InterlockedExchangeAdd64(&g_arraNum[threadID * 32], threadID + 1);
//InterlockedExchangeAdd64g_arraNum[threadID], threadID + 1);
}
DWORD dwEnd = GetTickCount();
printf("Thread: %I32u - Time: %I32u.\n", threadID, dwEnd - dwBegin);
return 0;
}
int main(int argc, char** argv)
{
__int8 buf[456];
SYSTEM_LOGICAL_PROCESSOR_INFORMATION* procInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION*)buf;
SYSTEM_LOGICAL_PROCESSOR_INFORMATION logProcInfo = {0};
DWORD dwSize = 456;
GetLogicalProcessorInformation(procInfo, &dwSize);
printf("Cache Line Size:%u\n", procInfo->Cache.LineSize);
DWORD dwBegin = GetTickCount();
std::vector<HANDLE> vThreads;
for (int i = 0; i < 8; i++)
{
HANDLE h = CreateThread(NULL,
0,
ParaInc,
(void*)i,
0,
NULL);
vThreads.push_back(h);
}
WaitForMultipleObjects(static_cast<DWORD>(vThreads.size()), &vThreads[0], TRUE, INFINITE);
DWORD dwEnd = GetTickCount();
printf("Total Time:%I32u\n", dwEnd - dwBegin);
return 0;
}
Show details
Hide details
Change log
r89
by changshuliu on Jul 9, 2011
Diff
add memory performance analyzer into tools folder
Go to:
/trunk/Tools/MemPerfor
...nk/Tools/MemPerfor/CachePerf.cpp
/trunk/Tools/MemPerfor/CppAlloc.cpp
/trunk/Tools/MemPerfor/ParaSum.cxx
/trunk/Tools/MemPerfor/WinHeap.cxx
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 1596 bytes, 62 lines
View raw file
Powered by
Google Project Hosting