-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathtest_serialization.py
More file actions
30 lines (24 loc) · 1.03 KB
/
test_serialization.py
File metadata and controls
30 lines (24 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright the Vortex contributors
import pickle
from typing import cast
import pytest
from pytest_benchmark.fixture import BenchmarkFixture # pyright: ignore[reportMissingTypeStubs]
import vortex as vx
@pytest.mark.parametrize("protocol", [4, 5], ids=lambda p: f"p{p}") # pyright: ignore[reportAny]
@pytest.mark.parametrize("operation", ["dumps", "loads", "roundtrip"])
@pytest.mark.benchmark(disable_gc=True)
def test_pickle(
benchmark: BenchmarkFixture,
array_fixture: vx.Array,
protocol: int,
operation: str,
):
benchmark.group = f"pickle_p{protocol}"
if operation == "dumps":
benchmark(lambda: pickle.dumps(array_fixture, protocol=protocol))
elif operation == "loads":
pickled_data = pickle.dumps(array_fixture, protocol=protocol)
benchmark(lambda: cast(object, pickle.loads(pickled_data)))
elif operation == "roundtrip":
benchmark(lambda: cast(object, pickle.loads(pickle.dumps(array_fixture, protocol=protocol))))