内存操作真的很快吗?memset、memcpy的性能如何呢?以下结果显示,消耗惊人!
100G内存的memset、memcpy消耗时间分别为:6766ms、17687ms;CPU均为51%.
代码:
#include "stdafx.h"
#include
void TestMemset(char *sData,int nSize)
{
memset(sData,0,nSize);
}
void TestMemcpy(char *sData,char *sOldData,int nSize)
{
memcpy(sData,sOldData,nSize);
}
int _tmain()
{
char *sData = new char[64*1024];
char *sOldData = new char[64*1024];
DWORD nDwRun = GetTickCount();
for (int nFor = 0;nFor <50;nFor++)
{
for(int n = 0; n <32000; n++)
{
TestMemset(sData,64*1024);
}
}
printf("Time=%u\r\n",GetTickCount() - nDwRun);
nDwRun = GetTickCount();
for (int nFor = 0;nFor <50;nFor++)
{
for(int n = 0; n <32000; n++)
{
TestMemcpy(sData,sOldData,64*1024);
}
}
printf("Time=%u\r\n",GetTickCount() - nDwRun);
int nWait =0;
scanf("%d",&nWait);
return 0;
}