为什么测试的TCMalloc不靠谱,性能反而差了
不说话,直接上码:
不说话,直接上码:
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#ifdef _DEBUG
#pragma comment(lib, "libtcmalloc_minimal-debug.lib")
#else
#pragma comment(lib, "libtcmalloc_minimal.lib")
#endif
int _tmain(int argc, _TCHAR* argv[])
{
DWORD pre = GetTickCount();
int i;
for ( i=0; i<100000; i++)
{
char * p1= new char[100];
char * p2= new char[200];
char * p3= new char[300];
char * p4= new char[500];
delete [] p1;
delete [] p2;
delete [] p3;
delete [] p4;
// char * p1=(char*)malloc(100);
// char * p2= (char*)malloc(200);
// char * p3= (char*)malloc(300);
// char * p4= (char*)malloc(500);
//
// free(p1);
// free(p2);
// free(p3);
// free(p4) ;
}
std::cout <<i<<"times cost (ms)"<< GetTickCount()-pre;
getchar();
return 0;
}
测试结果:
不加TC, 78ms
加 了TC,反而更长,156ms
环境:winxp sp3 vc2008