From ac204c85f98ab66cfb049f77ad9c9acf58b02bb2 Mon Sep 17 00:00:00 2001 From: vchamarthi Date: Tue, 16 Jun 2026 10:03:21 -0500 Subject: [PATCH] separate class for each ufunc --- benchmarks/benchmarks/micro/bench_micro.py | 38 ++++++++++++++-------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/benchmarks/benchmarks/micro/bench_micro.py b/benchmarks/benchmarks/micro/bench_micro.py index 5302f5bb..5b4b4ec5 100644 --- a/benchmarks/benchmarks/micro/bench_micro.py +++ b/benchmarks/benchmarks/micro/bench_micro.py @@ -1,8 +1,7 @@ """Micro-benchmarks for mkl_umath unary ufuncs. -Times each ufunc over a Cartesian product of - dtype in [float32, float64] - size in [10_000, 100_000, 1_000_000] +Each ufunc gets its own benchmark class (Bench_) so ASV renders a +separate grid tile per ufunc. Params are dtype x size only. Arrays are pre-allocated in setup() and reused across timing calls. Patching is applied once at package import via benchmarks._patch_setup. @@ -39,24 +38,35 @@ } -class BenchMicro: - params = ( - sorted(_UFUNC_CONFIGS.keys()), - ["float32", "float64"], - [10_000, 100_000, 1_000_000], - ) - param_names = ["ufunc", "dtype", "size"] - - def setup(self, ufunc, dtype, size): - cfg = _UFUNC_CONFIGS[ufunc] +def _make_bench(name, cfg): + def setup(self, dtype, size): rng = np.random.default_rng(42) self.x = rng.uniform(cfg["low"], cfg["high"], size).astype(dtype) self._func = cfg["func"] self._func(self.x) - def time_micro(self, ufunc, dtype, size): + def time_ufunc(self, dtype, size): self._func(self.x) + return type( + f"Bench_{name}", + (), + { + "params": (["float32", "float64"], [10_000, 100_000, 1_000_000]), + "param_names": ["dtype", "size"], + "setup": setup, + "time_ufunc": time_ufunc, + }, + ) + + +globals().update( + { + f"Bench_{name}": _make_bench(name, cfg) + for name, cfg in _UFUNC_CONFIGS.items() + } +) + class BenchArctan2: """Binary ufunc arctan2"""