首页 > 编程知识 正文

测试内存条读写速度的软件,如何测试内存带宽

时间:2023-05-04 00:06:13 阅读:260015 作者:4019

之前有写文章介绍了 mbw(https://blog.csdn.net/engrossment/article/details/88314722)以及 lmbench(https://blog.csdn.net/engrossment/article/details/83830363)。其中 mbw 的只是简单使用了 memcpy 系统调用进行测试,而 lmbench 里面的 bw_mem、stream 则给出了多种模式的带宽测试方式。查看其代码实现,比较复杂,而且加入了一些运算,使得在嵌入式的测试场景中,处理器成为了测试的瓶颈,无法测出更好的峰值。

于是参考 stream 的实现,简化了数据的读写,而且是读、写各自独立统计。代码如下。注意编译使用 -O3 优化级别编译。

#include <stdio.h>#include <stdint.h>#include <stdlib.h>#include <unistd.h>#include <sys/time.h>//NOTE, you should compile this program with gcc -O3#define N 10000000 // Count of array elements.// Return seconds since Epoch.double mysecond() { struct timeval tp; struct timezone tzp; gettimeofday(&tp, &tzp)

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。