-
Notifications
You must be signed in to change notification settings - Fork 0
/
mrbeats_profiller.py
46 lines (31 loc) · 1.17 KB
/
mrbeats_profiller.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
from array import array
import timeit
nb_samples = 44100
buf = array('h', b"\x00\x00" * nb_samples)
def func1():
for i in range(0, nb_samples):
buf[i] = 0
return buf
def func2():
return buf[0:nb_samples]
# print(timeit.repeat(setup="from __main__ import func1",stmt="func1()",repeat=3,number=100))
# print(timeit.repeat(setup="from __main__ import func2",stmt="func2()",repeat=3,number=100))
buf1 = array('h', b"\x00\x00" * nb_samples)
buf2 = array('h', b"\x00\x00" * nb_samples)
buf3 = array('h', b"\x00\x00" * nb_samples)
buf4 = array('h', b"\x00\x00" * nb_samples)
bufs = [buf1, buf2, buf3, buf4]
def func3():
for i in range(0, nb_samples):
buf[i] = 0
for j in range(0, len(bufs)):
buf[i] += bufs[j][i]
def func4():
s = [sum(x) for x in zip(*bufs)]
return array('h', s)
def func5():
s = map(sum, zip(*bufs))
return array('h', s)
# print(timeit.repeat(setup="from __main__ import func3",stmt="func3()",repeat=3,number=100))
print(timeit.repeat(setup="from __main__ import func4",stmt="func4()",repeat=3,number=100))
print(timeit.repeat(setup="from __main__ import func5",stmt="func5()",repeat=3,number=100))