-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyMark.py
More file actions
64 lines (57 loc) · 1.69 KB
/
Copy pathPyMark.py
File metadata and controls
64 lines (57 loc) · 1.69 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import time
import os
import tkinter as tk
import random
import math
print("PyMark")
start_1 = time.perf_counter()
count = 0
for i in range(20000000):
count += 1
end_1 = time.perf_counter()
time_1 = end_1 - start_1
print(f"Test 1 (Integer Loop): {time_1:.4f}s")
start_2 = time.perf_counter()
calc = 0.0
for i in range(5000000):
if (val := i * 0.0001) > 0:
calc += val / 3.14159
end_2 = time.perf_counter()
time_2 = end_2 - start_2
print(f"Test 2 (Floating-Point Math): {time_2:.4f}s")
filename = "pymark_temp.bin"
data = b"0" * (50 * 1024 * 1024)
start_3 = time.perf_counter()
with open(filename, "wb") as f:
f.write(data)
with open(filename, "rb") as f:
_ = f.read()
end_3 = time.perf_counter()
time_3 = end_3 - start_3
if os.path.exists(filename):
os.remove(filename)
print(f"Test 3 (Storage I/O Throughput): {time_3:.4f}s")
root = tk.Tk()
root.title("PyMark")
canvas = tk.Canvas(root, width=800, height=600, bg="black")
canvas.pack()
root.update()
start_4 = time.perf_counter()
colors = ["red", "green", "blue", "yellow", "white", "purple", "cyan", "orange"]
for _ in range(5000):
x0 = random.randint(0, 750)
y0 = random.randint(0, 550)
x1 = x0 + random.randint(10, 50)
y1 = y0 + random.randint(10, 50)
color = random.choice(colors)
if random.choice([True, False]):
canvas.create_rectangle(x0, y0, x1, y1, fill=color, outline="")
else:
canvas.create_oval(x0, y0, x1, y1, fill=color, outline="")
if _ % 100 == 0:
root.update()
root.update()
end_4 = time.perf_counter()
time_4 = end_4 - start_4
total_time = time_1 + time_2 + time_3 + time_4
print(f"Total: {total_time:.4f}s")