forked from sysprog21/lab0-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestsort.py
78 lines (62 loc) · 1.92 KB
/
testsort.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import subprocess
import re
import matplotlib.pyplot as plt
cmd_template = """option fail 0
option malloc 0
new
ih RAND {}
time
sort
time
free
"""
x_values = []
y1_values = []
y2_values = []
for i in range(1,100000,1000):
cmd_content = cmd_template.format(i)
file_name = f"./traces/sort_test.cmd"
with open(file_name, "w") as cmd_file:
cmd_file.write(cmd_content)
command = "perf stat -e cycles ./qtest -f ./traces/sort_test.cmd"
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.stderr:
cycles_match = re.search(r'\b(\d{1,3}(?:,\d{3})*\b)', result.stderr)
if cycles_match:
cycles_number = cycles_match.group(1)
cycles_number = int(cycles_number.replace(",", ""))
x_values.append(i)
y1_values.append(cycles_number)
else:
continue
cmd_template = """option fail 0
option malloc 0
new
ih RAND {}
time
lsort
time
free
"""
for i in range(1,100000,1000):
cmd_content = cmd_template.format(i)
file_name = f"./traces/sort_test.cmd"
with open(file_name, "w") as cmd_file:
cmd_file.write(cmd_content)
command = "perf stat -e cycles ./qtest -f ./traces/sort_test.cmd"
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.stderr:
cycles_match = re.search(r'\b(\d{1,3}(?:,\d{3})*\b)', result.stderr)
if cycles_match:
cycles_number = cycles_match.group(1)
cycles_number = int(cycles_number.replace(",", ""))
y2_values.append(cycles_number)
else:
continue
plt.plot(x_values, y1_values, label='my_sort', marker='x')
plt.plot(x_values, y2_values, label='list_sort', marker='x')
plt.title('Sort Performance')
plt.xlabel('Size of the Linked List')
plt.ylabel('Number of Cycles')
plt.legend()
plt.show()