-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisk-benchmark.py
More file actions
48 lines (40 loc) · 1.31 KB
/
disk-benchmark.py
File metadata and controls
48 lines (40 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os, time, tkinter as tk
from tkinter import ttk
def test_write_speed(path="testfile.bin", size_mb=1024):
block = b"0" * 1024 * 1024
start = time.time()
with open(path, "wb") as f:
for _ in range(size_mb):
f.write(block)
end = time.time()
os.remove(path)
return size_mb / (end - start)
def test_read_speed(path="testfile.bin", size_mb=100):
block = b"0" * 1024 * 1024
with open(path, "wb") as f:
for _ in range(size_mb):
f.write(block)
start = time.time()
with open(path, "rb") as f:
while f.read(1024 * 1024):
pass
end = time.time()
os.remove(path)
return size_mb / (end - start)
def run_test():
# write_speed = test_write_speed()
results = [test_write_speed() for _ in range(3)]
write_speed = sum(results) / len(results)
read_speed = test_read_speed()
write_label.config(text=f"Write Speed: {write_speed:.2f} MB/s")
read_label.config(text=f"Read Speed: {read_speed:.2f} MB/s")
root = tk.Tk()
root.title("Disk Speed Test")
root.geometry("300x150")
btn = ttk.Button(root, text="Run Test", command=run_test)
btn.pack(pady=10)
write_label = tk.Label(root, text="Write Speed: ---")
write_label.pack(pady=5)
read_label = tk.Label(root, text="Read Speed: ---")
read_label.pack(pady=5)
root.mainloop()