forked from sevagh/pitch-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.py
executable file
·54 lines (47 loc) · 1.57 KB
/
benchmark.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
#!/usr/bin/env python3
import os
import sys
import subprocess
import random
if __name__ == '__main__':
hyperfine = subprocess.Popen('hyperfine',
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = hyperfine.communicate()
if hyperfine.returncode != 0 and err and 'The following required arguments were not provided' not in str(err):
print('Hyperfine problems: {0}'.format(err), file=sys.stderr)
sys.exit(hyperfine.returncode)
pitches = [
83.3,
1337.0,
537.0,
699.9,
343.2,
2134.0,
1234.0,
555.5,
]
sizes = [
64000,
64303,
]
algo = None
try:
algo = sys.argv[1]
except IndexError:
algo = 'mpm'
for size in sizes:
for pitch in pitches:
sinewave_cmd = './bin/sinewave {0} {1} {2} 48000'.format(pitch, algo, size)
qrun = subprocess.Popen(
sinewave_cmd,
shell=True,
stdout=subprocess.PIPE).communicate()[0]
_, expect, got = qrun[:-1].decode('utf-8').split('\t')
expect = float(expect.split()[-1])
got = float(got.split()[-1])
print('Expect: {0:.2f}, Got: {1:.2f}, Error: {2:.2f}'.format(expect, got, (abs(expect - got)/expect)*100.0))
brun = subprocess.Popen(
"hyperfine --min-runs 10 --warmup 3 '{0}'".format(sinewave_cmd),
shell=True).communicate()