Skip to content

Commit 5da73cd

Browse files
committedJun 25, 2024
Add benchmark function
1 parent 1f97b32 commit 5da73cd

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed
 

‎pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ features = ["pyo3/extension-module"]
3636

3737
[project.optional-dependencies]
3838
test = [
39-
"pytest >= 7.4.2",
39+
"pytest >= 7.4.2", "pyperf >= 2.7.0"
4040
]
4141
[tool.maturin.dynamic]
4242
readme = {file = "README.md", content-type = "text/markdown"}

‎src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl CVM {
6767
}
6868

6969
#[pymodule]
70-
fn cvmcount(_py: Python, m: Bound<'_, PyModule>) -> PyResult<()> {
70+
fn count_distinct(_py: Python, m: Bound<'_, PyModule>) -> PyResult<()> {
7171
m.add_class::<CVM>()?;
7272
// m.add_function(wrap_pyfunction!(version, m)?)?;
7373

‎tests/bench.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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=10_000_000)
13+
14+
counter = CVM(0.8, 0.1, 100000)
15+
16+
runner = pyperf.Runner()
17+
runner.bench_func(
18+
"10 million 7-digit random positive integers",
19+
add_elems,
20+
counter,
21+
random_integers,
22+
)
23+
count = counter.calculate_final_result()

0 commit comments

Comments
 (0)