Skip to content

Commit 9393d0d

Browse files
authored
Merge pull request #227 from vchamarthi/asv-benchmarks
refactor(benchmarks): one grid tile per ufunc in micro suite
2 parents c2ba6bd + a2d43b1 commit 9393d0d

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

benchmarks/benchmarks/micro/bench_micro.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""Micro-benchmarks for mkl_umath unary ufuncs.
22
3-
Times each ufunc over a Cartesian product of
4-
dtype in [float32, float64]
5-
size in [10_000, 100_000, 1_000_000]
3+
Each ufunc gets its own benchmark class (Bench_<name>) so ASV renders a
4+
separate grid tile per ufunc. Params are dtype x size only.
65
76
Arrays are pre-allocated in setup() and reused across timing calls.
87
Patching is applied once at package import via benchmarks._patch_setup.
@@ -39,24 +38,35 @@
3938
}
4039

4140

42-
class BenchMicro:
43-
params = (
44-
sorted(_UFUNC_CONFIGS.keys()),
45-
["float32", "float64"],
46-
[10_000, 100_000, 1_000_000],
47-
)
48-
param_names = ["ufunc", "dtype", "size"]
49-
50-
def setup(self, ufunc, dtype, size):
51-
cfg = _UFUNC_CONFIGS[ufunc]
41+
def _make_bench(name, cfg):
42+
def setup(self, dtype, size):
5243
rng = np.random.default_rng(42)
5344
self.x = rng.uniform(cfg["low"], cfg["high"], size).astype(dtype)
5445
self._func = cfg["func"]
5546
self._func(self.x)
5647

57-
def time_micro(self, ufunc, dtype, size):
48+
def time_ufunc(self, dtype, size):
5849
self._func(self.x)
5950

51+
return type(
52+
f"Bench_{name}",
53+
(),
54+
{
55+
"params": (["float32", "float64"], [10_000, 100_000, 1_000_000]),
56+
"param_names": ["dtype", "size"],
57+
"setup": setup,
58+
"time_ufunc": time_ufunc,
59+
},
60+
)
61+
62+
63+
globals().update(
64+
{
65+
f"Bench_{name}": _make_bench(name, cfg)
66+
for name, cfg in _UFUNC_CONFIGS.items()
67+
}
68+
)
69+
6070

6171
class BenchArctan2:
6272
"""Binary ufunc arctan2"""

0 commit comments

Comments
 (0)