From 59ccb8c06052e890f2f502835ff639b31a3f30ba Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Sun, 27 Aug 2023 21:56:26 +0200 Subject: [PATCH] BENCH: fix issues with Methods0D benchmarks in `bench_ufunc.py` --- benchmarks/benchmarks/bench_ufunc.py | 43 ++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/benchmarks/benchmarks/bench_ufunc.py b/benchmarks/benchmarks/bench_ufunc.py index 45f2f312f4bb..72beb163567e 100644 --- a/benchmarks/benchmarks/bench_ufunc.py +++ b/benchmarks/benchmarks/bench_ufunc.py @@ -135,27 +135,54 @@ def time_ndarray_meth(self, methname, npdtypes): getattr(operator, methname)(*[self.vals, 2]) -class Methods0D(Benchmark): +class Methods0DBoolComplex(Benchmark): """Zero dimension array methods """ - params = [['__bool__', '__complex__', '__invert__', - '__float__', '__int__'], TYPES1] + params = [['__bool__', '__complex__'], + TYPES1] param_names = ['methods', 'npdtypes'] timeout = 10 def setup(self, methname, npdtypes): self.xarg = np.array(3, dtype=npdtypes) - if (npdtypes.startswith('complex') and - methname in ['__float__', '__int__']) or \ - (npdtypes.startswith('int') and methname == '__invert__'): - # Skip - raise NotImplementedError def time_ndarray__0d__(self, methname, npdtypes): meth = getattr(self.xarg, methname) meth() +class Methods0DFloatInt(Benchmark): + """Zero dimension array methods + """ + params = [['__int__', '__float__'], + [dt for dt in TYPES1 if not dt.startswith('complex')] + ] + param_names = ['methods', 'npdtypes'] + timeout = 10 + + def setup(self, methname, npdtypes): + self.xarg = np.array(3, dtype=npdtypes) + + def time_ndarray__0d__(self, methname, npdtypes): + meth = getattr(self.xarg, methname) + meth() + + + +class Methods0DInvert(Benchmark): + """Zero dimension array methods + """ + params = ['int16', 'int32', 'int64'] + param_names = ['npdtypes'] + timeout = 10 + + def setup(self, npdtypes): + self.xarg = np.array(3, dtype=npdtypes) + + def time_ndarray__0d__(self, npdtypes): + self.xarg.__invert__() + + class MethodsV1(Benchmark): """ Benchmark for the methods which take an argument """