-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime_plotter.py
More file actions
64 lines (55 loc) · 2.37 KB
/
runtime_plotter.py
File metadata and controls
64 lines (55 loc) · 2.37 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 matplotlib.pyplot as plt
import csv
from pprint import pprint
def check_header(firstLine:list):
"""
Check if first line is a header.
Parameters
----------
firstLine:list -> first line of csv-file
"""
for elem in firstLine:
for letter in elem:
if letter.isalpha():
return True
return False
def read_csv(file_path):
x:list = [] # x-data (Elements)
yOwn:list = [] # y-data for own implementation (Runtime in ns)
yStd:list = [] # y-data for standard implementation (Runtime in ns)
with open(file_path, 'r') as file:
reader = csv.reader(file) # read csv-file
header = next(reader)
data = [] # data list
if not check_header(header): # if first line is no header
data.append(header) # append header to data list
for row in reader: # iterate over rows
x.append(int(row[0])) # append x-data
yOwn.append(int(row[1])) # append y-data for own implementation
yStd.append(int(row[2])) # append y-data for standard implementation
data.append(row) # append row to data list
return x, yOwn, yStd, header, data
def plot_runtime(x:list, yOwn:list, yStd:list, header:list, funcName:str, xAccuracy:str="ns"):
plt.plot(x, yOwn, label=header[1]) # plot own implementation
plt.plot(x, yStd, label=header[2]) # plot standard implementation
plt.title(f"{funcName} - {header[1]} vs. {header[2]}") # title
plt.xlabel('Anzahl Elemente') # x-axis label
plt.ylabel(f'Laufzeit ({xAccuracy})') # y-axis label
plt.legend() # legend
return plt
if __name__ == '__main__':
# ### Beispiel fuer eine Datei in einem Plot ###
# # removeFront
# x, yOwn, yStd, header, data = read_csv('listRemoveFrontRuntimeTest.csv')
# plot = plot_runtime(x, yOwn, yStd, header, "removeFront()")
# plot.savefig("removeFront.png")
# plot.show()
# ### Beispiel fuer 2 Dateien in einem Plot ###
# # insertAfter
# x, yOwn, yStd, header, data = read_csv('dListInsertAfterRuntimeTest.csv')
# plot_runtime(x, yOwn, yStd, header, "insertAfter()")
# x, yOwn, yStd, header, data = read_csv('listInsertAfterRuntimeTest.csv')
# plot = plot_runtime(x, yOwn, yStd, header, "insertAfter()")
# plot.savefig("insertAfter.png")
# plot.show()
pass