Skip to content

Commit 47130fa

Browse files
committed
Add backend loading benchmark
1 parent f424551 commit 47130fa

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

asv_bench/benchmarks/plotting.py

+32
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import importlib
2+
import sys
3+
14
import matplotlib
25
import numpy as np
6+
import pkg_resources
37

48
from pandas import (
59
DataFrame,
610
DatetimeIndex,
711
Series,
12+
__file__ as pd_file,
813
date_range,
914
)
1015

@@ -13,6 +18,8 @@
1318
except ImportError:
1419
from pandas.tools.plotting import andrews_curves
1520

21+
from pandas.plotting._core import _get_plot_backend
22+
1623
matplotlib.use("Agg")
1724

1825

@@ -99,4 +106,29 @@ def time_plot_andrews_curves(self):
99106
andrews_curves(self.df, "Name")
100107

101108

109+
class BackendLoading:
110+
def setup(self):
111+
dist = pkg_resources.get_distribution("pandas")
112+
if dist.module_path not in pd_file:
113+
# We are running from a non-installed pandas, and this benchmark is
114+
# invalid
115+
raise NotImplementedError("Testing a non-installed pandas")
116+
117+
spec = importlib.machinery.ModuleSpec("my_backend", None)
118+
mod = importlib.util.module_from_spec(spec)
119+
mod.plot = lambda *args, **kwargs: 1
120+
121+
backends = pkg_resources.get_entry_map("pandas")
122+
my_entrypoint = pkg_resources.EntryPoint(
123+
"pandas_plotting_backend", mod.__name__, dist=dist
124+
)
125+
backends["pandas_plotting_backends"][mod.__name__] = my_entrypoint
126+
for i in range(1000):
127+
backends["pandas_plotting_backends"][str(i)] = my_entrypoint
128+
sys.modules["my_backend"] = mod
129+
130+
def time_get_plot_backend(self):
131+
_get_plot_backend("my_backend")
132+
133+
102134
from .pandas_vb_common import setup # noqa: F401 isort:skip

0 commit comments

Comments
 (0)