mysql使用Tcmalloc的性能测试代码

 

 
  
  1. #include <stdlib.h> 
  2. #include <stdio.h> 
  3. #include <unistd.h> 
  4. #include <time.h> 
  5. include <sys/time.h> 
  6. #include <pthread.h> 
  7. #define MAX_COUNT 1000*1000 
  8. void fun(int a) 
  9.         char* ptr = (char*)malloc(i); 
  10.          free(ptr); 
  11. void* fun_thread(void*) 
  12.         int a = 0
  13.          int b = 1
  14.         while(a++<MAX_COUNT
  15.          { 
  16.                    b ++; 
  17.                    fun(b); 
  18.                    if ( b>1024 ) 
  19.                             b = 1
  20.          } 
  21. #define MSECOND 1000000 
  22. int main() 
  23.          struct timeval tpstart,tpend; 
  24.          float timeuse; 
  25.         gettimeofday(&tpstart,NULL); 
  26.          pthread_t _deliver_t; 
  27.          pthread_create(&_deliver_t, NULL, fun_thread, NULL); 
  28.          int a = 0
  29.          int b = 1
  30.          while(a++<MAX_COUNT
  31.          { 
  32.                    b++; 
  33.                    fun(a); 
  34.                   if ( b > 1024 ) 
  35.                            b = 1
  36.                    //usleep(1); 
  37.          } 
  38.          gettimeofday(&tpend,NULL); 
  39.          timeuse=MSECOND*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec; 
  40.          timeuse/=MSECOND; 
  41.          printf("Used Time:%f\n", timeuse); 
  42.          return 0; 
  43. 注:代码部分引自网络佳人(名字已忘记,呵呵),欢迎沟通,交流。