-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcomparePerformance.py
executable file
·85 lines (67 loc) · 2.51 KB
/
comparePerformance.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
79
80
81
82
83
84
85
#!/usr/bin/python
import sys
def mean(nums):
return sum(nums) / len(nums)
def get_times(csv):
times = {}
with open(csv) as f:
for line in f:
name, time_ = line.split(",")
time_ = float(time_)
if time_ == 0:
print("Warning - {} was 0 for ".format(name, csv))
continue
times[name] = float(time_)
return times
def print_output_markdown(ratios):
# Keep this print so Jenkins can extract what's in between for GitHub
print("---RESULTS---")
print("| Name | Old Result | New Result | Ratio | Performance change( 1 - new / old ) |")
print("| ------------- |------------- | ------------- | ------------- | ------------- |")
total = 0
for r in ratios:
print("| " + r + " | " +
str(round(ratios[r]['old'], 2)) + " | " +
str(round(ratios[r]['new'], 2)) + " | " +
str(round(ratios[r]['ratio'], 2)) + " | " +
str(round(ratios[r]['change'], 2)) + ("% faster" if round(ratios[r]['change'], 2) > 0 else "% slower" ) + " |"
)
total = total + ratios[r]['ratio']
print("Mean result: " + str(total / len(ratios)))
# Keep this print so Jenkins can extract what's in between for GitHub
print("---RESULTS---")
def print_output_csv(ratios):
print("Name, Old Result, New Result, Ratio, Performance change( 1 - new / old )")
total = 0
for r in ratios:
print(r + ", " +
str(round(ratios[r]['old'], 2)) + ", " +
str(round(ratios[r]['new'], 2)) + ", " +
str(round(ratios[r]['ratio'], 2)) + ", " +
str(round(ratios[r]['change'], 2)) + ("% faster" if round(ratios[r]['change'], 2) > 0 else "% slower" )
)
total = total + ratios[r]['ratio']
print("Mean result: " + str(total / len(ratios)))
if __name__ == "__main__":
csv1 = sys.argv[1]
csv2 = sys.argv[2]
output_type = sys.argv[3]
times1, times2 = map(get_times, [csv1, csv2])
ratios = {}
for n in times1:
key = "performance.compilation" if "compilation" in n else n
old = times1[n]
new = times2[key]
ratio = old / new
ratios[key] = {
"old": old,
"new": new,
"ratio": ratio,
"change": (1 - new / old) * 100
}
if output_type == "markdown":
print_output_markdown(ratios)
elif output_type == "csv":
print_output_csv(ratios)
elif not output_type:
print_output_csv(ratios)