linux u盘 慢_Linux系统下测U盘(USB口)速度的工具和方法

http://www.firekyrin.com/archives/2974.html

dd命令测试

以下两条

time dd if=/dev/zero of=/mnt/usb/4g bs=1024 count=4000000

time dd if=/mnt/usb/4g bs=128k | dd of=/dev/null

USB速度测试命令

瑞士军刀busybox里面有hdparm命令,也可以用来测试读写速度,不过这个命令有点老了。

hdparm -Tt /dev/sdb1

输出结果:

Timing buffer-cache

reads: 68 MB

in 0.51 seconds = 136192 kB/s

Timing buffered disk reads: 30

MB in 3.00 seconds = 10211 kB/s

中断号:

169: 136 stx7105-level ehci_hcd:usb1

Timing buffer-cache

reads: 76 MB

in 0.51 seconds = 152415 kB/s

Timing buffered disk

reads: 3 MB

in 3.21 seconds = 955 kB/s

编程测试USB速度

如果愿意,我们还可以用编写程序的方法来测试USB口的速度,以下程序可以用来参考。

#include

#include

#include

#include

#include

#include

char filename[]=”dev/sdb1″;

int main(int argc, char** argv)

{

FILE *pfile;

struct timeval pretime,curtime;

float usec1,usec2,totalsec;

int num;

int count=20;

pfile = fopen(filename,”r”);

char *pmalloc = NULL;

if(pfile==NULL)

{

perror(“open fail\n”);

return 1;

}

pmalloc = (char *)malloc(1024*1024*1); //8MiB

if(pmalloc == NULL)

{

perror(“malloc fail\n”);

goto out2;

}

while(count)

{

gettimeofday(&pretime,NULL);

num = fread(pmalloc,1,1024*1024*1,pfile); //8MiB

if(num<0)

{

perror(“read fail\n”);

goto out1;

}

gettimeofday(&curtime,NULL);

usec1=(float)curtime.tv_usec/1000000.0f;

usec2=(float)pretime.tv_usec/1000000.0f;

totalsec=(float)(curtime.tv_sec-pretime.tv_sec)+(usec1-usec2);

printf(“—%.3fMiB/s—\n”,((float)num/(1024*1024))/totalsec);

count–;

}

out1:

free(pmalloc);

out2:

fclose(pfile);

return 0;

}

如果用以上的几个方法分别测试,结果会发现测试的结果会稍有不同,不过火麒麟会更倾向于第一个方法。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值