Skip to content

Commit

Permalink
chore: use the fixture for the doc benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
art049 committed Feb 6, 2025
1 parent 5a96ba4 commit 608bd39
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions tests/benchmarks/test_bench_doc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Benches from the CodSpeed Getting Started Documentation."""

import pytest


def count_even_fast(arr):
"""Count the number of even numbers in an array."""
Expand All @@ -12,16 +10,14 @@ def count_even_fast(arr):
return even


@pytest.mark.benchmark
def test_count_even_fast():
assert count_even_fast(range(10_000)) == 5000
def test_count_even_fast(benchmark):
assert benchmark(count_even_fast, range(10_000)) == 5000


def count_even_slow(arr):
"""Count the number of even numbers in an array."""
return sum(1 for x in arr if x % 2 == 0)


@pytest.mark.benchmark
def test_count_even_slow():
assert count_even_slow(range(10_000)) == 5000
def test_count_even_slow(benchmark):
assert benchmark(count_even_slow, range(10_000)) == 5000

0 comments on commit 608bd39

Please sign in to comment.