|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import sys |
| 4 | +from typing import Any |
| 5 | + |
3 | 6 | import numpy as np |
4 | 7 | import pytest |
5 | 8 | from pytest_benchmark.fixture import BenchmarkFixture |
6 | 9 |
|
7 | 10 | import nitypes.bintime as bt |
8 | 11 |
|
9 | 12 |
|
10 | | -LIST_10: list[bt.TimeDelta] = [bt.TimeDelta(float(value)) for value in np.arange(-10, 10, 0.3)] |
11 | | -LIST_100: list[bt.TimeDelta] = [bt.TimeDelta(float(value)) for value in np.arange(-100, 100, 0.3)] |
12 | | -LIST_1000: list[bt.TimeDelta] = [ |
13 | | - bt.TimeDelta(float(value)) for value in np.arange(-1000, 1000, 0.3) |
14 | | -] |
15 | | -LIST_10000: list[bt.TimeDelta] = [ |
16 | | - bt.TimeDelta(float(value)) for value in np.arange(-10000, 10000, 0.3) |
17 | | -] |
| 13 | +LIST_1 = [bt.TimeDelta(0.3)] |
| 14 | +LIST_10 = [bt.TimeDelta(float(value)) for value in np.arange(-10, 10, 0.3)] |
| 15 | +LIST_100 = [bt.TimeDelta(float(value)) for value in np.arange(-100, 100, 0.3)] |
| 16 | +LIST_1000 = [bt.TimeDelta(float(value)) for value in np.arange(-1000, 1000, 0.3)] |
| 17 | +LIST_10000 = [bt.TimeDelta(float(value)) for value in np.arange(-10000, 10000, 0.3)] |
| 18 | + |
| 19 | +FAST_CASES = (LIST_1,) |
| 20 | +BIG_O_CASES = (LIST_1, LIST_10, LIST_100, LIST_1000, LIST_10000) # Useful for local measurements |
| 21 | + |
| 22 | + |
| 23 | +benchmark_options: dict[str, Any] = {} |
| 24 | +if sys.implementation.name == "pypy": |
| 25 | + # See #182 -- PR/CI workflows spend too much time on PyPy benchmarks |
| 26 | + benchmark_options["warmup"] = False |
| 27 | + benchmark_options["min_rounds"] = 1 |
| 28 | + benchmark_options["max_time"] = 0.5 |
18 | 29 |
|
19 | 30 |
|
20 | | -@pytest.mark.benchmark(group="timedelta_array_construct", min_rounds=100) |
21 | | -@pytest.mark.parametrize("constructor_list", (LIST_10, LIST_100, LIST_1000, LIST_10000)) |
| 31 | +@pytest.mark.benchmark(group="timedelta_array_construct", **benchmark_options) |
| 32 | +@pytest.mark.parametrize("constructor_list", FAST_CASES) |
22 | 33 | def test___bt_timedelta_array___construct( |
23 | 34 | benchmark: BenchmarkFixture, |
24 | 35 | constructor_list: list[bt.TimeDelta], |
25 | 36 | ) -> None: |
26 | 37 | benchmark(bt.TimeDeltaArray, constructor_list) |
27 | 38 |
|
28 | 39 |
|
29 | | -@pytest.mark.benchmark(group="timedelta_array_extend", min_rounds=100) |
30 | | -@pytest.mark.parametrize("extend_list", (LIST_10, LIST_100, LIST_1000, LIST_10000)) |
| 40 | +@pytest.mark.benchmark(group="timedelta_array_extend", **benchmark_options) |
| 41 | +@pytest.mark.parametrize("extend_list", FAST_CASES) |
31 | 42 | def test___bt_timedelta_array___extend( |
32 | 43 | benchmark: BenchmarkFixture, |
33 | 44 | extend_list: list[bt.TimeDelta], |
|
0 commit comments