jemalloc 测试
jemalloc安装
wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2 tar xjf jemalloc-3.6.0.tar.bz2 cd jemalloc-3.6.0 ./configure make && make install echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf ldconfig
测试代码
/*============================================================================= # FileName: test.cpp # Desc: G # Author: Pugna # Email: 860009944@qq.com # HomePage: http://www.cnblogs.com/pugna/ # Version: 0.0.1 # LastChange: 2014-10-22 09:47:01 # History: =============================================================================*/ #include <malloc.h> #include <stdio.h> #include <sys/time.h> static const int n=1000000; static const int msecond=1000000; int main(){ void * p[n]; struct timeval t_start,t_end; float timeuse; gettimeofday(&t_start,NULL); for(int i=0;i<n;i++){ p[i]=malloc(10); } gettimeofday(&t_end,NULL); timeuse=msecond*(t_end.tv_sec-t_start.tv_sec)+t_end.tv_usec-t_start.tv_usec; timeuse/=msecond; printf("malloc use time:%f\r\n",timeuse); gettimeofday(&t_start,NULL); for(int i=0;i<n;i++){ p[i]=realloc(p[i],15); } gettimeofday(&t_end,NULL); timeuse=msecond*(t_end.tv_sec-t_start.tv_sec)+t_end.tv_usec-t_start.tv_usec; timeuse/=msecond; printf("realloc use time:%f\r\n",timeuse); return 0; }
没用jemalloc
使用jemalloc