关于tcmalloc\malloc和new
生活随笔
收集整理的這篇文章主要介紹了
关于tcmalloc\malloc和new
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
? ? ? 最近在測(cè)試tcmalloc性能的時(shí)候發(fā)現(xiàn)了一個(gè)現(xiàn)象!!!!就是new似乎很消耗性能!!直接上代碼!
? ? ? ?
#include "time.h" #include <gperftools/tcmalloc.h> using namespace std;#define MAX_SIZE 500000//MsgDuplex _msg_list;struct MsgToPut {UINT _wr_ptr;UINT _rd_ptr;UINT _length;CHAR _base[1024]; };int main() {long long int start = get_os_system_time();MessageBlock* mbs[MAX_SIZE];for(int i=0;i<MAX_SIZE;i++){mbs[i] = new MessageBlock(1024);delete mbs[i];}long long int end = get_os_system_time();printf("%d\n",end - start);MsgToPut* mtp[MAX_SIZE];for(int i=0;i<MAX_SIZE;i++){mtp[i] = (MsgToPut*)tc_malloc(sizeof(MsgToPut));tc_delete(mtp[i]);}start = get_os_system_time();printf("%d\n",start - end);return 0; }MessageBlock 在博文http://www.cnblogs.com/archy_yu/archive/2012/09/07/2674909.html中有介紹!!!
?我們看下打印數(shù)據(jù)!
28
10
?既然new在執(zhí)行的時(shí)候運(yùn)行了構(gòu)造函數(shù),那么我們也做一個(gè)reset操作; 并且在每次mtp[i] = (MsgToPut*)tc_malloc(sizeof(MsgToPut));之后執(zhí)行reset函數(shù),但是效果影響不大,打印數(shù)據(jù)為:
28
12
new 相比malloc 和 tcmalloc要消耗性能!!!而且很客觀!!!
轉(zhuǎn)載于:https://www.cnblogs.com/archy_yu/archive/2013/03/22/2976137.html
總結(jié)
以上是生活随笔為你收集整理的关于tcmalloc\malloc和new的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 解读主流CDN厂商的节点数据
- 下一篇: java url 授权,Spring M