mysql使用Tcmalloc的性能测试代码
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <time.h>
- include <sys/time.h>
- #include <pthread.h>
- #define MAX_COUNT 1000*1000
- void fun(int a)
- {
- char* ptr = (char*)malloc(i);
- free(ptr);
- }
- void* fun_thread(void*)
- {
- int a = 0;
- int b = 1;
- while(a++<MAX_COUNT)
- {
- b ++;
- fun(b);
- if ( b>1024 )
- b = 1;
- }
- }
- #define MSECOND 1000000
- int main()
- {
- struct timeval tpstart,tpend;
- float timeuse;
- gettimeofday(&tpstart,NULL);
- pthread_t _deliver_t;
- pthread_create(&_deliver_t, NULL, fun_thread, NULL);
- int a = 0;
- int b = 1;
- while(a++<MAX_COUNT)
- {
- b++;
- fun(a);
- if ( b > 1024 )
- b = 1;
- //usleep(1);
- }
- gettimeofday(&tpend,NULL);
- timeuse=MSECOND*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
- timeuse/=MSECOND;
- printf("Used Time:%f\n", timeuse);
- return 0;
- }
- 注:代码部分引自网络佳人(名字已忘记,呵呵),欢迎沟通,交流。
转载于:https://blog.51cto.com/haicang/1080535