-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark-schoolbook.py
executable file
·60 lines (56 loc) · 1.7 KB
/
benchmark-schoolbook.py
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
#!/usr/bin/env python3
import serial
import subprocess
dev = serial.Serial("/dev/ttyUSB0", 115200)
results = []
for i in range(1, 250):
binary = f"benchmark-schoolbook_{i}.bin"
print(f">>> making {binary}")
subprocess.run(["make", binary])
print("done")
print(f">>> flashing {binary}")
subprocess.run(["st-flash", "--reset", "write", binary, "0x8000000"])
print("done")
state = 'waiting'
marker = b''
while True:
x = dev.read()
if state == 'waiting':
if x == b'=':
marker += x
continue
# If we saw at least 5 equal signs, assume we've probably started
elif marker.count(b'=') > 5:
state = 'beginning'
vector = []
print(" .. found output marker..")
if state == 'beginning':
if x == b'=':
continue
else:
state = 'reading'
elif state == 'reading':
if x == b'#':
break
else:
vector.append(x)
vector = b''.join(vector).decode('utf-8').split("\n")
n = 0
for i in range(len(vector)):
if vector[i] == "n: ":
n = int(vector[i+1])
if vector[i] == "cycles: ":
cycles = int(vector[i+1])
print("## found results")
if vector[i] == "ERROR!":
print("## FOUND AN ERROR!")
results.append([n, cycles])
print("| N | cycles ")
for result in results:
print(f"| {result[0]} | {result[1]}")
print("cleaning up...")
subprocess.run(["make", "clean"])
print("done...")
print("| N | cycles ")
for result in results:
print(f"| {result[0]} | {result[1]}")