Skip to content

Commit 206c13b

Browse files
committed
add more struct and module tests
1 parent 1054b16 commit 206c13b

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎tests/prof/perf/test_module.py‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
import subprocess
22
import sys
33

4+
import pytest
45

5-
def test_import_time(benchmark):
6+
7+
@pytest.mark.parametrize(
8+
"module_name",
9+
[
10+
"msgspec",
11+
"msgspec.structs",
12+
"msgspec.json",
13+
"msgspec.msgpack",
14+
"msgspec.inspect",
15+
"msgspec.yaml",
16+
"msgspec.toml",
17+
],
18+
)
19+
def test_import_time(benchmark, module_name):
620
# also measures interpreter startup etc., but is the best we can do now, since we
721
# don't have a fully isolated module, and some per-process global state, so
822
# re-importing purely within the current interpreter doesn't get reliable timings
923
def do_import():
10-
subprocess.run([sys.executable, "-c", "import msgspec"], check=True)
24+
subprocess.run([sys.executable, "-c", f"import {module_name}"], check=True)
1125

1226
do_import() # execute once to reduce possibility of a super cold FS cache
1327

‎tests/prof/perf/test_structs.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ class C{n}(Struct, order=True):
1616
e: int
1717
"""
1818

19+
TEMPLATE_EMPTY = """
20+
class C{n}(Struct, order=True):
21+
pass
22+
"""
23+
1924
TEMPLATE_WITH_TAG_TRUE = """
2025
class C{n}(Struct, order=True, tag=True):
2126
a: int
@@ -54,9 +59,14 @@ class Item(msgspec.Struct, order=True):
5459
e: int
5560

5661

62+
class EmptyStruct(msgspec.Struct):
63+
pass
64+
65+
5766
@pytest.mark.parametrize(
5867
"template",
5968
[
69+
pytest.param(TEMPLATE_EMPTY, id="empty"),
6070
pytest.param(TEMPLATE, id="basic"),
6171
pytest.param(TEMPLATE_WITH_TAG_TRUE, id="tagged"),
6272
pytest.param(TEMPLATE_WITH_CUSTOM_TAG, id="custom_tag"),
@@ -109,6 +119,15 @@ def test_create(benchmark):
109119
)
110120

111121

122+
@pytest.mark.memory
123+
def test_empty_struct_create(benchmark: BenchmarkFixture):
124+
# empty struct to measure pure overhead without any type nodes
125+
benchmark.pedantic(
126+
lambda: [EmptyStruct() for _ in range(N)],
127+
warmup_rounds=10,
128+
)
129+
130+
112131
@pytest.mark.memory
113132
def test_equality(benchmark):
114133
needle = Item(N - 1, N - 1, N - 1, N - 1, N - 1)

0 commit comments

Comments
 (0)