Skip to content

Commit 4f60a18

Browse files
committed
test: add benches from the documentation's getting started
1 parent 547fad1 commit 4f60a18

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/benchmarks/test_bench_doc.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Benches from the CodSpeed Getting Started Documentation."""
2+
3+
import pytest
4+
5+
6+
def sum_of_squares_fast(arr) -> int:
7+
total = 0
8+
for x in arr:
9+
total += x * x
10+
return total
11+
12+
13+
def sum_of_squares_slow(arr) -> int:
14+
return sum(map(lambda x: x**2, arr)) # noqa: C417
15+
16+
17+
@pytest.mark.benchmark
18+
def test_sum_squares_fast():
19+
assert sum_of_squares_fast(range(1000)) == 332833500
20+
21+
22+
@pytest.mark.benchmark
23+
def test_sum_squares_slow():
24+
assert sum_of_squares_slow(range(1000)) == 332833500

0 commit comments

Comments
 (0)