Linux系统下硬盘建议EXT4格式
import os
import time
# 所有要测试的挂载路径(根据你的截图填写)
mount_points = [
"/data/usb0",
"/data/usb1",
"/data/usb2",
"/data/usb4",
"/data/usb5",
"/data/usb6",
"/home",
]
# 测试文件大小(MB)
file_size_mb = 1024 # 1GB
block_size = 1024 * 1024 # 1MB
data = b'0' * block_size
def test_disk_speed(mount_path):
test_file = os.path.join(mount_path, "test_speed_file.bin")
# 写入测试
start_time = time.time()
try:
with open(test_file, "wb") as f:
for _ in range(file_size_mb):
f.write(data)
os.sync()
write_time = time.time() - start_time
write_speed = file_size_mb / write_time
except Exception as e:
return (mount_path, None, None, f"写入失败: {e}")
# 读取测试
try:
start_time = time.time()
with open(test_file, "rb") as f:
while f.read(block_size):
pass
read_time = time.time() - start_time
read_speed = file_size_mb / read_time
except Exception as e:
return (mount_path, write_speed, None, f"读取失败: {e}")
# 删除文件
os.remove(test_file)
return (mount_path, write_speed, read_speed, "成功")
# 运行测试
results = []
for path in mount_points:
print(f"正在测试:{path}")
result = test_disk_speed(path)
results.append(result)
# 打印结果
print("\n=== 测试结果 ===")
for path, w_speed, r_speed, status in results:
if w_speed is not None and r_speed is not None:
print(f"{path} => 写入: {w_speed:.2f} MB/s, 读取: {r_speed:.2f} MB/s")
else:
print(f"{path} => {status}")