memset bzero性能测试 ltrace strace用法

2016-10-30 11:59:00
admin
原创 1800
摘要:memset bzero性能测试 ltrace strace用法

一、memset和bzero性能测试

1 void bzero(void *s, size_t n); #include <strings.h>

2 void *memset(void *s, int c, size_t n); #include <string.h>

3 bzero已经被废弃,建议使用memset


代码下载memset_perf.cpp

使用方法:./memset_perf start_sleep_time loop_count block_size


calcMalloc性能数据(./memset_perf  3 10000 `expr 1024 \* 1024 \* 2`):

CLOCKS_PER_SECOND is 1000000.
cost is 730000, average is 0.000073.

CLOCKS_PER_SECOND is 1000000.
cost is 770000, average is 0.000077.

CLOCKS_PER_SECOND is 1000000.
cost is 700000, average is 0.000070.


malloc和free性能结论:

1000次malloc和free大概73微秒


calcMemset性能数据(./memset_perf  3 10000 `expr 1024 \* 1024 \* 2`):

CLOCKS_PER_SECOND is 1000000.
cost is 39460000, average is 0.001315.

CLOCKS_PER_SECOND is 1000000.
cost is 14910000, average is 0.001491.

CLOCKS_PER_SECOND is 1000000.
cost is 11620000, average is 0.001162.


memset性能结论:

memset初始化4M数据大概1.2毫秒


二、ltrace和strace用法

ltrace:A library call tracer

strace:trace system calls and signals

-c 计数并且汇总


./memset_perf  3 10000 `expr 1024 \* 1024 \* 2`


ps -ef | grep perf
root     17545 17256 99 18:00 pts/0    00:56:57 ./memset_perf 3 10000 2097152


ltrace -p 17545 -c 
% time     seconds  usecs/call     calls      function
------ ----------- ----------- --------- --------------------
 95.44    5.528267        3109      1778 memset
  2.36    0.136656         153       890 free
  2.20    0.127690         143       890 malloc
------ ----------- ----------- --------- --------------------
100.00    5.792613                  3558 total

发表评论
评论通过审核之后才会显示。