-
Notifications
You must be signed in to change notification settings - Fork 10
/
benchmark_np.py
103 lines (85 loc) · 2.46 KB
/
benchmark_np.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import os
import os.path
import timeit
import argparse
import utils
import numpy as np
import functools
import loaders
def get_files(dir, extension):
audio_files = []
dir = os.path.expanduser(dir)
for root, _, fnames in sorted(os.walk(dir)):
for fname in fnames:
if fname.endswith(extension):
path = os.path.join(root, fname)
item = path
audio_files.append(item)
return audio_files
class AudioFolder(object):
def __init__(
self,
root,
extension='wav'
):
self.root = os.path.expanduser(root)
self.data = []
self.audio_files = get_files(dir=self.root, extension=extension)
def __getitem__(self, index):
return self.audio_files[index]
def __len__(self):
return len(self.audio_files)
def test_np_loading(fp, lib):
load_function = getattr(loaders, 'load_' + lib)
audio = load_function(fp)
if np.max(audio) > 0:
return True
else:
return False
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--ext', type=str, default="wav")
args = parser.parse_args()
columns = [
'ext',
'lib',
'duration',
'time',
]
store = utils.DF_writer(columns)
# audio formats to be bench
# libraries to be benchmarked
libs = [
'scipy',
'stempeg',
'soxbindings',
'ar_ffmpeg',
'aubio',
'pydub',
'soundfile',
'librosa',
'scipy_mmap'
]
for lib in libs:
print("Testing: %s" % lib)
for root, dirs, fnames in sorted(os.walk('AUDIO')):
for audio_dir in dirs:
duration = int(audio_dir)
dataset = AudioFolder(
os.path.join(root, audio_dir),
extension=args.ext
)
# for fp in dataset.audio_files:
for fp in dataset.audio_files:
time = min(timeit.repeat(
functools.partial(test_np_loading, fp, lib),
number=3,
repeat=3
))
store.append(
ext=args.ext,
lib=lib,
duration=duration,
time=time,
)
store.df.to_pickle("results/benchmark_%s_%s.pickle" % ("np", args.ext))