Skip to content

Commit 41e6ddd

Browse files
authored
Fix #182 and reduce benchmark test times (#184)
- Add and use a length-1 list test case by default for the array tests - Detect PyPy and use additional benchmark options - Remove type hints from constants Signed-off-by: Joe Friedrichsen <[email protected]>
1 parent 6ef6af1 commit 41e6ddd

File tree

2 files changed

+46
-22
lines changed

2 files changed

+46
-22
lines changed

tests/benchmark/bintime/test_datetime_array.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,50 @@
11
from __future__ import annotations
22

3+
import sys
4+
from typing import Any
5+
36
import numpy as np
47
import pytest
58
from pytest_benchmark.fixture import BenchmarkFixture
69

710
import nitypes.bintime as bt
811

912

10-
LIST_10: list[bt.DateTime] = [
11-
bt.DateTime.from_offset(bt.TimeDelta(float(offset))) for offset in np.arange(0, 10, 0.3)
12-
]
13-
LIST_100: list[bt.DateTime] = [
13+
LIST_1 = [bt.DateTime.from_offset(bt.TimeDelta(0.3))]
14+
LIST_10 = [bt.DateTime.from_offset(bt.TimeDelta(float(offset))) for offset in np.arange(0, 10, 0.3)]
15+
LIST_100 = [
1416
bt.DateTime.from_offset(bt.TimeDelta(float(offset))) for offset in np.arange(0, 100, 0.3)
1517
]
16-
LIST_1000: list[bt.DateTime] = [
18+
LIST_1000 = [
1719
bt.DateTime.from_offset(bt.TimeDelta(float(offset))) for offset in np.arange(0, 1000, 0.3)
1820
]
19-
LIST_10000: list[bt.DateTime] = [
21+
LIST_10000 = [
2022
bt.DateTime.from_offset(bt.TimeDelta(float(offset))) for offset in np.arange(0, 10000, 0.3)
2123
]
2224

25+
FAST_CASES = (LIST_1,)
26+
BIG_O_CASES = (LIST_1, LIST_10, LIST_100, LIST_1000, LIST_10000) # Useful for local measurements
27+
28+
29+
benchmark_options: dict[str, Any] = {}
30+
if sys.implementation.name == "pypy":
31+
# See #182 -- PR/CI workflows spend too much time on PyPy benchmarks
32+
benchmark_options["warmup"] = False
33+
benchmark_options["min_rounds"] = 1
34+
benchmark_options["max_time"] = 0.5
35+
2336

24-
@pytest.mark.benchmark(group="datetime_array_construct", min_rounds=100)
25-
@pytest.mark.parametrize("constructor_list", (LIST_10, LIST_100, LIST_1000, LIST_10000))
37+
@pytest.mark.benchmark(group="datetime_array_construct", **benchmark_options)
38+
@pytest.mark.parametrize("constructor_list", FAST_CASES)
2639
def test___bt_datetime_array___construct(
2740
benchmark: BenchmarkFixture,
2841
constructor_list: list[bt.DateTime],
2942
) -> None:
3043
benchmark(bt.DateTimeArray, constructor_list)
3144

3245

33-
@pytest.mark.benchmark(group="datetime_array_extend", min_rounds=100)
34-
@pytest.mark.parametrize("extend_list", (LIST_10, LIST_100, LIST_1000, LIST_10000))
46+
@pytest.mark.benchmark(group="datetime_array_extend", **benchmark_options)
47+
@pytest.mark.parametrize("extend_list", FAST_CASES)
3548
def test___bt_datetime_array___extend(
3649
benchmark: BenchmarkFixture,
3750
extend_list: list[bt.DateTime],

tests/benchmark/bintime/test_timedelta_array.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
from __future__ import annotations
22

3+
import sys
4+
from typing import Any
5+
36
import numpy as np
47
import pytest
58
from pytest_benchmark.fixture import BenchmarkFixture
69

710
import nitypes.bintime as bt
811

912

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
1829

1930

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)
2233
def test___bt_timedelta_array___construct(
2334
benchmark: BenchmarkFixture,
2435
constructor_list: list[bt.TimeDelta],
2536
) -> None:
2637
benchmark(bt.TimeDeltaArray, constructor_list)
2738

2839

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)
3142
def test___bt_timedelta_array___extend(
3243
benchmark: BenchmarkFixture,
3344
extend_list: list[bt.TimeDelta],

0 commit comments

Comments
 (0)