File: test_bench_doc.py

package info (click to toggle)
pytest-codspeed 4.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,608 kB
  • sloc: ansic: 9,792; python: 2,066; sh: 41; makefile: 14
file content (24 lines) | stat: -rw-r--r-- 505 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Benches from the CodSpeed Getting Started Documentation."""

import pytest


def sum_of_squares_fast(arr) -> int:
    total = 0
    for x in arr:
        total += x * x
    return total


def sum_of_squares_slow(arr) -> int:
    return sum(map(lambda x: x**2, arr))  # noqa: C417


@pytest.mark.benchmark
def test_sum_squares_fast():
    assert sum_of_squares_fast(range(1000)) == 332833500


@pytest.mark.benchmark
def test_sum_squares_slow():
    assert sum_of_squares_slow(range(1000)) == 332833500