-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathbenchmark_imports.py
More file actions
56 lines (42 loc) · 1.53 KB
/
benchmark_imports.py
File metadata and controls
56 lines (42 loc) · 1.53 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Benchmarks for import times of the spatialdata package and its submodules.
Each ``timeraw_*`` function returns a snippet of Python code that asv runs in
a fresh interpreter, so the measured time reflects a cold import with an empty
module cache.
"""
from collections.abc import Callable
from typing import Any
def _timeraw(func: Any) -> Any:
"""Set asv benchmark attributes for a cold-import timeraw function."""
func.repeat = 5 # number of independent subprocess measurements
func.number = 1 # must be 1: second import in same process hits module cache
return func
@_timeraw
def timeraw_import_spatialdata() -> str:
"""Time a bare ``import spatialdata``."""
return """
import spatialdata
"""
@_timeraw
def timeraw_import_SpatialData() -> str:
"""Time importing the top-level ``SpatialData`` class."""
return """
from spatialdata import SpatialData
"""
@_timeraw
def timeraw_import_read_zarr() -> str:
"""Time importing ``read_zarr`` from the top-level namespace."""
return """
from spatialdata import read_zarr
"""
@_timeraw
def timeraw_import_models_elements() -> str:
"""Time importing the main element model classes."""
return """
from spatialdata.models import Image2DModel, Labels2DModel, PointsModel, ShapesModel, TableModel
"""
@_timeraw
def timeraw_import_transformations() -> str:
"""Time importing the ``spatialdata.transformations`` submodule."""
return """
from spatialdata.transformations import Affine, Scale, Translation, Sequence
"""