forked from tayloraswift/swift-png
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark
executable file
·58 lines (50 loc) · 2.12 KB
/
benchmark
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 os, sys, subprocess, glob, datetime, argparse
import benchmark_latest, benchmark_crunch, benchmark_toolchains
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--trials', type = int, nargs = 3,
default = (10, 5, 20),
help = 'number of trials to run, for decompression, compression, and historical toolchain benchmarks, respectively')
parser.add_argument('-s', '--save', action = 'store_true',
help = 'save the collected data for later use')
parser.add_argument('-l', '--load', action = 'store_true',
help = 'use precomputed data if available')
arguments = parser.parse_args()
prefix = 'benchmarks/results'
try:
os.mkdir(prefix)
except FileExistsError:
pass
if arguments.load:
with open('{0}/commit'.format(prefix), 'r') as file:
commit = file.read().rstrip()
else:
commit = subprocess.run(('git', 'rev-parse', 'HEAD'), capture_output = True).stdout.decode('utf-8').rstrip()
with open('{0}/commit'.format(prefix), 'w') as file:
file.write('{0}\n'.format(commit))
fields = {
'date' : datetime.date.today().strftime('%B %d, %Y'),
'commit' : '[`{0}`](https://github.com/kelvin13/swift-png/commit/{1})'.format(commit[:7], commit),
'tool' : '[`{0}`](../{0})'.format(sys.argv[0]),
}
images = sorted(tuple(os.path.splitext(os.path.basename(path))[0]
for path in glob.glob('tests/compression/baseline/*.png')))
fields.update(benchmark_latest.benchmark(arguments.trials[:2],
images = images,
save = arguments.save,
load = arguments.load,
prefix = prefix))
fields.update(benchmark_crunch.benchmark(
images = images,
save = arguments.save,
load = arguments.load,
prefix = prefix))
fields.update(benchmark_toolchains.benchmark(arguments.trials[2],
image = 'rgb8-color-photographic',
save = arguments.save,
load = arguments.load,
prefix = prefix))
with open('benchmarks/template.md', 'r') as file:
template = file.read()
with open('benchmarks/README.md', 'w') as file:
file.write(template.format( ** fields ))