1 Star 0 Fork 0

sylijinlei/cputest

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
memtest.c 897 Bytes
一键复制 编辑 原始数据 按行查看 历史
sylijinlei 提交于 2020-06-23 15:24 +08:00 . first commit
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
int gettime(int i)
{
static struct timeval tv1;
struct timeval tv2;
if(i == 0)
{
gettimeofday(&tv1, NULL);
return 0;
}else
{
gettimeofday(&tv2, NULL);
return tv2.tv_sec * 1000000 + tv2.tv_usec - tv1.tv_sec * 1000000 - tv1.tv_usec;
}
}
/*#define SIZE (1024 * 1024 * 10)*/
#define SIZE (1024 * 1024 * 10)
long long buf[SIZE];
int main(int argc, char *argv[])
{
int i;
int time;
memset(buf, 0, SIZE * 8);
gettime(0);
for(i = 0; i < SIZE; i++)
{
buf[i] = i;
}
time = gettime(1);
printf("time1 = %d\n", time);
gettime(0);
for(i = 0; i < SIZE; i++)
{
buf[i] = i;
}
time = gettime(1);
printf("time2 = %d\n", time);
printf("speed: %dMB/S\n", SIZE * 8 / time);
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sylijinlei/cputest.git
git@gitee.com:sylijinlei/cputest.git
sylijinlei
cputest
cputest
master

搜索帮助