Skip to content

Commit 6ca12b0

Browse files
committed
Add memory perf benchmark
1 parent 92169bc commit 6ca12b0

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,13 @@ count = counter.calculate_final_result()
3838
# you can keep adding elements if you wish
3939
```
4040

41+
# Perf
42+
## Memory, 10e8 random 7-digit positive integers
43+
Allocation of integer array: 763 MiB
44+
45+
`count_distinct`: 768 MiB
46+
47+
`np.unique`: 1.7 GiB
48+
4149
## Note
4250
If you're thinking about using this library, you presumably know that it only provides an estimate (within the specified bounds), similar to something like HyperLogLog. You are trading accuracy for speed!

tests/bench_numpy.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import numpy as np
2+
import pyperf
3+
4+
def add_elems(elems):
5+
return np.unique(elems)
6+
7+
8+
# Generate 10 million random 7-digit integers
9+
random_integers = np.random.randint(low=1000000, high=10000000, size=10_000_000)
10+
11+
runner = pyperf.Runner()
12+
runner.bench_func(
13+
"10 million 7-digit random positive integers: numpy",
14+
add_elems, random_integers
15+
)
16+

tests/memory_count_distinct.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import numpy as np
2+
import pyperf
3+
from count_distinct import CVM
4+
5+
6+
def add_elems(counter, elems):
7+
for elem in elems:
8+
counter.add(elem)
9+
10+
11+
# Generate 10 million random 7-digit integers
12+
random_integers = np.random.randint(low=1000000, high=10000000, size=100_000_000)
13+
14+
counter = CVM(0.8, 0.1, 100000)
15+
16+
add_elems(counter, random_integers)
17+
count = counter.calculate_final_result()

tests/memory_numpy.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import numpy as np
2+
import memray
3+
4+
def add_elems(elems):
5+
return np.unique(elems)
6+
7+
# Generate 100 million random 7-digit integers
8+
random_integers = np.random.randint(low=1000000, high=10000000, size=100_000_000)
9+
10+
res = add_elems(random_integers)

0 commit comments

Comments
 (0)