|
1 | 1 | """Micro-benchmarks for mkl_umath unary ufuncs. |
2 | 2 |
|
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. |
6 | 5 |
|
7 | 6 | Arrays are pre-allocated in setup() and reused across timing calls. |
8 | 7 | Patching is applied once at package import via benchmarks._patch_setup. |
|
39 | 38 | } |
40 | 39 |
|
41 | 40 |
|
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): |
52 | 43 | rng = np.random.default_rng(42) |
53 | 44 | self.x = rng.uniform(cfg["low"], cfg["high"], size).astype(dtype) |
54 | 45 | self._func = cfg["func"] |
55 | 46 | self._func(self.x) |
56 | 47 |
|
57 | | - def time_micro(self, ufunc, dtype, size): |
| 48 | + def time_ufunc(self, dtype, size): |
58 | 49 | self._func(self.x) |
59 | 50 |
|
| 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 | + |
60 | 70 |
|
61 | 71 | class BenchArctan2: |
62 | 72 | """Binary ufunc arctan2""" |
|
0 commit comments