summaryrefslogtreecommitdiff
path: root/benchmarks
diff options
context:
space:
mode:
authorRohit Goswami <rog32@hi.is>2022-12-05 00:53:05 +0000
committerRohit Goswami <rog32@hi.is>2022-12-05 02:46:03 +0000
commitecf195df053b619de21871653431154033cbd462 (patch)
tree03b084359a7f2d23846a2ca44244041512ddee29 /benchmarks
parent4c4e803c3866fd31440e8db395142eeb2c2ffbd4 (diff)
downloadnumpy-ecf195df053b619de21871653431154033cbd462.tar.gz
BENCH: Port ma/bench.py to asv
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/benchmarks/bench_ma.py146
1 files changed, 146 insertions, 0 deletions
diff --git a/benchmarks/benchmarks/bench_ma.py b/benchmarks/benchmarks/bench_ma.py
index b214c0b86..cccb5a4cf 100644
--- a/benchmarks/benchmarks/bench_ma.py
+++ b/benchmarks/benchmarks/bench_ma.py
@@ -111,3 +111,149 @@ class Concatenate(Benchmark):
def time_it(self, mode, n):
np.ma.concatenate(self.args)
+
+
+class MAFunctions1v(Benchmark):
+ param_names = ['mtype', 'func', 'msize']
+ params = [['np', 'np.ma'],
+ ['sin', 'log', 'sqrt'],
+ ['small', 'big']]
+
+ def setup(self, mtype, func, msize):
+ xs = np.random.uniform(-1, 1, 6).reshape(2, 3)
+ m1 = [[True, False, False], [False, False, True]]
+ xl = np.random.uniform(-1, 1, 100*100).reshape(100, 100)
+ maskx = xl > 0.8
+ self.nmxs = np.ma.array(xs, mask=m1)
+ self.nmxl = np.ma.array(xl, mask=maskx)
+
+ def time_functions_1v(self, mtype, func, msize):
+ # fun = {'np.ma.sin': np.ma.sin, 'np.sin': np.sin}[func]
+ fun = eval(f"{mtype}.{func}")
+ if msize == 'small':
+ fun(self.nmxs)
+ elif msize == 'big':
+ fun(self.nmxl)
+
+
+class MAMethod0v(Benchmark):
+ param_names = ['method', 'msize']
+ params = [['ravel', 'transpose', 'compressed', 'conjugate'],
+ ['small', 'big']]
+
+ def setup(self, method, msize):
+ xs = np.random.uniform(-1, 1, 6).reshape(2, 3)
+ m1 = [[True, False, False], [False, False, True]]
+ xl = np.random.uniform(-1, 1, 100*100).reshape(100, 100)
+ maskx = xl > 0.8
+ self.nmxs = np.ma.array(xs, mask=m1)
+ self.nmxl = np.ma.array(xl, mask=maskx)
+
+ def time_methods_0v(self, method, msize):
+ if msize == 'small':
+ mdat = self.nmxs
+ elif msize == 'big':
+ mdat = self.nmxl
+ getattr(mdat, method)()
+
+
+class MAFunctions2v(Benchmark):
+ param_names = ['mtype', 'func', 'msize']
+ params = [['np', 'np.ma'],
+ ['multiply', 'divide', 'power'],
+ ['small', 'big']]
+
+ def setup(self, mtype, func, msize):
+ # Small arrays
+ xs = np.random.uniform(-1, 1, 6).reshape(2, 3)
+ ys = np.random.uniform(-1, 1, 6).reshape(2, 3)
+ m1 = [[True, False, False], [False, False, True]]
+ m2 = [[True, False, True], [False, False, True]]
+ self.nmxs = np.ma.array(xs, mask=m1)
+ self.nmys = np.ma.array(ys, mask=m2)
+ # Big arrays
+ xl = np.random.uniform(-1, 1, 100*100).reshape(100, 100)
+ yl = np.random.uniform(-1, 1, 100*100).reshape(100, 100)
+ maskx = xl > 0.8
+ masky = yl < -0.8
+ self.nmxl = np.ma.array(xl, mask=maskx)
+ self.nmyl = np.ma.array(yl, mask=masky)
+
+ def time_functions_2v(self, mtype, func, msize):
+ fun = eval(f"{mtype}.{func}")
+ if msize == 'small':
+ fun(self.nmxs, self.nmys)
+ elif msize == 'big':
+ fun(self.nmxl, self.nmyl)
+
+
+class MAMethodGetItem(Benchmark):
+ param_names = ['margs', 'msize']
+ params = [[0, (0, 0), [0, -1]],
+ ['small', 'big']]
+
+ def setup(self, margs, msize):
+ xs = np.random.uniform(-1, 1, 6).reshape(2, 3)
+ m1 = [[True, False, False], [False, False, True]]
+ xl = np.random.uniform(-1, 1, 100*100).reshape(100, 100)
+ maskx = xl > 0.8
+ self.nmxs = np.ma.array(xs, mask=m1)
+ self.nmxl = np.ma.array(xl, mask=maskx)
+
+ def time_methods_getitem(self, margs, msize):
+ if msize == 'small':
+ mdat = self.nmxs
+ elif msize == 'big':
+ mdat = self.nmxl
+ getattr(mdat, '__getitem__')(margs)
+
+
+class MAMethodSetItem(Benchmark):
+ param_names = ['margs', 'mset', 'msize']
+ params = [[0, (0, 0), (-1, 0)],
+ [17, np.ma.masked],
+ ['small', 'big']]
+
+ def setup(self, margs, mset, msize):
+ xs = np.random.uniform(-1, 1, 6).reshape(2, 3)
+ m1 = [[True, False, False], [False, False, True]]
+ xl = np.random.uniform(-1, 1, 100*100).reshape(100, 100)
+ maskx = xl > 0.8
+ self.nmxs = np.ma.array(xs, mask=m1)
+ self.nmxl = np.ma.array(xl, mask=maskx)
+
+ def time_methods_setitem(self, margs, mset, msize):
+ if msize == 'small':
+ mdat = self.nmxs
+ elif msize == 'big':
+ mdat = self.nmxl
+ getattr(mdat, '__setitem__')(margs, mset)
+
+
+class Where(Benchmark):
+ param_names = ['mtype', 'msize']
+ params = [['np', 'np.ma'],
+ ['small', 'big']]
+
+ def setup(self, mtype, msize):
+ # Small arrays
+ xs = np.random.uniform(-1, 1, 6).reshape(2, 3)
+ ys = np.random.uniform(-1, 1, 6).reshape(2, 3)
+ m1 = [[True, False, False], [False, False, True]]
+ m2 = [[True, False, True], [False, False, True]]
+ self.nmxs = np.ma.array(xs, mask=m1)
+ self.nmys = np.ma.array(ys, mask=m2)
+ # Big arrays
+ xl = np.random.uniform(-1, 1, 100*100).reshape(100, 100)
+ yl = np.random.uniform(-1, 1, 100*100).reshape(100, 100)
+ maskx = xl > 0.8
+ masky = yl < -0.8
+ self.nmxl = np.ma.array(xl, mask=maskx)
+ self.nmyl = np.ma.array(yl, mask=masky)
+
+ def time_where(self, mtype, msize):
+ fun = eval(f"{mtype}.where")
+ if msize == 'small':
+ fun(self.nmxs > 2, self.nmxs, self.nmys)
+ elif msize == 'big':
+ fun(self.nmxl > 2, self.nmxl, self.nmyl)