-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeed_test.py
More file actions
83 lines (67 loc) · 3.17 KB
/
Copy pathspeed_test.py
File metadata and controls
83 lines (67 loc) · 3.17 KB
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
import wavelets as wl
import time
import csv
import pywt
import numpy as np
lengths = [100, 200, 300, 400, 500, 600, 700, 800, 900]
lengths += [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000]
loops = 100000
# create a csv file to store the results
with open('./speed_tests/pywt_dwt_duration.csv', mode='w') as results_file:
results_writer = csv.writer(results_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
results_writer.writerow(['Length', 'Average time', 'Max time', 'Min time', 'Standard deviation'])
for length in lengths:
x = np.random.rand(length)
# time the function
times = []
for i in range(loops):
start = time.time()
ca, cd = pywt.dwt(x, 'db1')
end = time.time()
times.append(end-start)
results_writer.writerow([str(length), str(sum(times)/len(times)), str(max(times)), str(min(times)), str(np.std(times))])
print("pywt dwt done")
with open('./speed_tests/wavelet_dwt_duration.csv', mode='w') as results_file:
results_writer = csv.writer(results_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
results_writer.writerow(['Length', 'Average time', 'Max time', 'Min time', 'Standard deviation'])
for length in lengths:
x = np.random.rand(length)
# time the function
times = []
lpf_D, hpf_D, lpf_R, hpf_R =wl.getFilters("db1")
for i in range(loops):
start = time.time()
ca, cd = wl.dwt(x, lpf_D, hpf_D)
end = time.time()
times.append(end-start)
results_writer.writerow([str(length), str(sum(times)/len(times)), str(max(times)), str(min(times)), str(np.std(times))])
print("wavelet dwt done")
with open('./speed_tests/pywt_idwt_duration.csv', mode='w') as results_file:
results_writer = csv.writer(results_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
results_writer.writerow(['Length', 'Average time', 'Max time', 'Min time', 'Standard deviation'])
for length in lengths:
x = np.random.rand(length)
ca, cd = pywt.dwt(x, 'db1')
# time the function
times = []
for i in range(loops):
start = time.time()
pywt.idwt(ca, cd, 'db1')
end = time.time()
times.append(end-start)
results_writer.writerow([str(length), str(sum(times)/len(times)), str(max(times)), str(min(times)), str(np.std(times))])
print("pywt idwt done")
with open('./speed_tests/wavelet_idwt_duration.csv', mode='w') as results_file:
results_writer = csv.writer(results_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
results_writer.writerow(['Length', 'Average time', 'Max time', 'Min time', 'Standard deviation'])
for length in lengths:
x = np.random.rand(length)
ca, cd = wl.dwt(x, lpf_D, hpf_D)
# time the function
times = []
for i in range(loops):
start = time.time()
wl.idwt(ca, cd, len(x), lpf_R, hpf_R)
end = time.time()
times.append(end-start)
results_writer.writerow([str(length), str(sum(times)/len(times)), str(max(times)), str(min(times)), str(np.std(times))])