立即注册 登录
气象家园 返回首页

一大碗年糕的个人空间 http://bbs.06climate.com/?116087 [收藏] [复制] [分享] [RSS]

日志

测试挂载设备的速度

已有 91 次阅读2025-4-10 16:46

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}")

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

返回顶部