
for i in {0..1000}; do dd if=/dev/zero of=$i bs=1M count=1; done import threading import time def test(fn): file = open(str(fn), "rb") bytes = file.read(1) file.close() # print(fn, len(bytes)) def foo(): pass if __name__ == "__main__": ts = list() start_time = time.perf_counter () for i in range(1000): ts.append(threading.Thread(target=test, args=(i%1000,))) # ts.append(threading.Thread(target=foo)) ts[-1].start() for t in ts: t.join() end_time = time.perf_counter () print(end_time - start_time) import threading import time def test(fn): file = open(str(fn), "rb") # bytes = file.read(1) 与 a.py 相比就仅仅注释了这一句 file.close() # print(fn, len(bytes)) def foo(): pass if __name__ == "__main__": ts = list() start_time = time.perf_counter () for i in range(1000): ts.append(threading.Thread(target=test, args=(i%1000,))) # ts.append(threading.Thread(target=foo)) ts[-1].start() for t in ts: t.join() end_time = time.perf_counter () print(end_time - start_time) 在机械硬盘,固态上以及空载的结果分别是 0.07257, 0.07181, 0.0668.二者的差距微乎其微. 我了解到 7200rpm 的机械硬盘随机 4k 的速度大概在 0.5MB 左右.[https://superuser.com/questions/1595841/very-slow-random-read-write-on-hdd]
根据我的测试可得 4kB * 1000 / (0.07257s - 0.0668s) = 693240.901 KB/s [滑稽] 小弟我疑惑万分, 不知是不是目前的测试仍然在硬盘的缓存之上,所以测不出实际性能,还是其他什么原因.希望有知晓老哥的提点一二.
1 haiyang1992 2022-02-18 03:29:07 +08:00 via Android 原因之一可能你这 load 太小了,又跑这么多线程,处理 system call 的开销占了大部分的运行时间,并且 cpu context switch 过程也能掩盖掉一部分 io 的时间 |
2 Sylv 2022-02-18 06:45:32 +08:00 系统对读写是有缓存的。 |
3 F281M6Dh8DXpD1g2 2022-02-18 08:23:27 +08:00 via iPhone 都写到 file system cache 里了,测了个寂寞 |
4 murmur 2022-02-18 09:11:36 +08:00 不建议自己折腾这些,如果你想测云就佛系,云的硬盘就是离谱 如果你想有参考,用 windows 的 crystal 或者是 hdtunes 等测试软件,一定有相对可信的、大家都用的,才好有参考对比 |
5 msg7086 2022-02-18 09:56:58 +08:00 via Android 测内存读写速度吗? |
6 destinyzou 2022-02-18 10:02:27 +08:00 建议用 fio 吧,资料多,文档丰富。 |