Skip to content

Commit 301e64a

Browse files
authored
Merge pull request adafruit#1084 from v923z/master
update benchmark.py
2 parents 917226f + beccaff commit 301e64a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ulab_Crunch_Numbers_Fast/benchmark.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ def normalized_rms(values):
1616
return math.sqrt(samples_sum / len(values))
1717

1818
def normalized_rms_ulab(values):
19+
# this function works with ndarrays only
1920
minbuf = ulab.numerical.mean(values)
2021
values = values - minbuf
2122
samples_sum = ulab.numerical.sum(values * values)
2223
return math.sqrt(samples_sum / len(values))
2324

24-
2525
# Instead of using sensor data, we generate some data
2626
# The amplitude is 5000 so the rms should be around 5000/1.414 = 3536
2727
nums_list = [int(8000 + math.sin(i) * 5000) for i in range(100)]
@@ -33,8 +33,10 @@ def timeit(s, f, n=100):
3333
x = f()
3434
t1 = time.monotonic_ns()
3535
r = (t1 - t0) * 1e-6 / n
36-
print("%-20s : %8.3fms [result=%f]" % (s, r, x))
36+
print("%-30s : %8.3fms [result=%f]" % (s, r, x))
3737

3838
print("Computing the RMS value of 100 numbers")
3939
timeit("traditional", lambda: normalized_rms(nums_list))
40-
timeit("ulab", lambda: normalized_rms_ulab(nums_array))
40+
timeit("ulab, with ndarray, some implementation in python", lambda: normalized_rms_ulab(nums_array))
41+
timeit("ulab only, with list", lambda: ulab.numerical.std(nums_list))
42+
timeit("ulab only, with ndarray", lambda: ulab.numerical.std(nums_array))

0 commit comments

Comments
 (0)