-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathmetacall-benchmarks-merge.py
58 lines (47 loc) · 1.57 KB
/
metacall-benchmarks-merge.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
#!/usr/bin/python3
import json
import os
import sys
# Validate arguments
if len(sys.argv) != 2:
print('Invalid number of arguments, you should pass the location of the benchmarks.')
print('Usage: python3 metacall-benchmarks-merge.py ${CMAKE_BINARY_DIR}/benchmarks')
exit(1)
# Validate the benchmark path
if not os.path.isdir(sys.argv[1]):
print('The directory \'' + sys.argv[1] + '\' does not exist or is not a valid path.')
exit(2)
# Search all benchmarks and merge them
output = {}
for file in os.listdir(sys.argv[1]):
if file.endswith('.json'):
f = open(os.path.join(sys.argv[1], file), 'r')
# Sanitize the data (https://github.com/google/benchmark/issues/784)
# '-Infinity', 'Infinity', 'NaN'
def sanitize(arg):
c = {
'-Infinity': sys.float_info.min, # -float('inf')
'Infinity': sys.float_info.max, # float('inf')
'NaN': 0 # float('nan')
}
# TODO: Eventually solve this from the root of problem in Windows
print('Warning: Got value "' + arg + '" in the test ' + file + ', review why it is failing')
return c[arg]
data = json.loads(f.read(), parse_constant=sanitize)
if not output:
output = data
else:
for benchmark in data['benchmarks']:
output['benchmarks'].append(benchmark)
f.close()
# Check if we found data
if not output:
print('The directory \'' + sys.argv[1] + '\' does not contain any benchmark.')
exit(3)
# Rename the binary file
output['context']['executable'] = 'benchmarks'
# Store the result
dest = os.path.join(sys.argv[1], 'metacall-benchmarks.json')
f = open(dest, 'w+')
json.dump(output, f, indent = 4)
f.close()