-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresults-analyze.py
82 lines (71 loc) · 2.37 KB
/
results-analyze.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
import json
data = {}
languageNames = ["c", "c++", "c#", "java", "typescript", "javascript", "lua", "python", "ruby"]
def minutesToSeconds(minutes):
return minutes * 60
def analyze(language, data):
with open(f"benchmarks/results/{language}.txt", 'r') as f:
data[language] = {}
contents = f.read()
sections = contents.split(">> ")
sections = sections[1:]
for section in sections:
section = section.split("\n")
function = section[0]
data[language][function] = []
for line in section[1:]:
if line.startswith("Time spent:"):
time = line.split(": ")[1]
if("ms" in time):
time = time.replace("ms", "")
time = str(float(time) / 1000)
if("," in time):
timeSections = time.split(",")
time = str(minutesToSeconds(float(timeSections[0])) + float(timeSections[1]))
if(":" in time):
innerSections = time.split(" ")
timeSections = innerSections[0].split(":")
time = minutesToSeconds(float(timeSections[0])) + float(timeSections[1]) * 60
time = float(time)
data[language][function].append(time)
return data
def average(data):
return {
language: {
function: sum(data[language][function]) / len(data[language][function])
for function in data[language]
}
for language in data
}
def getConfig():
with open("config.json", 'r') as f:
return json.load(f)
def createAnalysisFile(data):
functions = ["Hello World", "Factorial of 20", "Summation of 1000000", "50th Recursive Fibonacci", "50th Iterative Fibonacci", "Linear Search; Maximum in 1000000", "Print Triangle of 100 elements"]
avgData = average(data)
languages = []
string = ""
for language in avgData:
languages.append(language)
string += "#Function,"
for language in languages:
string += f"{language.capitalize()},"
string = string[:-1]
string += "\n"
for i in range(len(functions)):
string += f"{functions[i]},"
for language in languages:
string += f"{avgData[language][str(i)]:.7f},"
string = string[:-1]
string += "\n"
with open("output-data.csv", 'w') as f:
f.write(string)
return string
def analyzeAll(data):
for language in languageNames:
try:
data = analyze(language, data)
except FileNotFoundError:
continue
analyzeAll(data)
createAnalysisFile(data)