首页 > 技术文章 > Linux下测试SSD固态硬盘写入速度

imapla 2014-12-12 09:26 原文

最近买了一个256GB的SSD固态硬盘,想测试一下写入速度,于是如下操作。

部分代码:

 1 gettimeofday(&start, NULL);
 2 int fd = open("test1.dat", O_RDWR|O_CREAT);
 3 if (fd < 0){
 4     printf("open error!\n");
 5     return 0;
 6 }
 7 lseek(fd, 0, SEEK_SET);
 8 write(fd, pData, DATA_LEN);
 9 close(fd);
10 gettimeofday(&end, NULL);
11 // 显示占用时间, 单位是us
12 diff = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec start.tv_usec);
13 printf("the data length is %d\n Byte", DATA_LEN);
14 printf("the difference is %ld us\n", diff);

测试一,数据大小 288,000 byte,5次取最长的时间,则写入速度约为 288000 byte / 2058us =  133.46 MB/s


 

测试二,数据大小 1,440,000 byte = 1.37MB,5次取最长的时间,则 写入速度约为 1440000 byte / 9356 us = 146.78 MB/s


 

测试三,数据大小 14,400,000 byte = 13.7MB,5次取最长时间,则写入速度约为 14400000 byte / 100234 us = 137.01MB/s

 

推荐阅读