diff options
author | Marten van Kerkwijk <mhvk@astro.utoronto.ca> | 2018-06-28 18:58:23 -0400 |
---|---|---|
committer | Marten van Kerkwijk <mhvk@astro.utoronto.ca> | 2018-06-29 15:31:49 -0400 |
commit | 2fa37890ccba346629e574ad1411928fb52cff43 (patch) | |
tree | 3e65158b3c624d2354be173f907f0ae46176ccd1 /benchmarks | |
parent | c0a333e9c9ee3d96acd3e038daf65974462d8baa (diff) | |
download | numpy-2fa37890ccba346629e574ad1411928fb52cff43.tar.gz |
BENCH: add ufunc argument parsing benchmarks.
Diffstat (limited to 'benchmarks')
-rw-r--r-- | benchmarks/benchmarks/bench_ufunc.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/benchmarks/benchmarks/bench_ufunc.py b/benchmarks/benchmarks/bench_ufunc.py index eb9c3cf3b..5d5eae251 100644 --- a/benchmarks/benchmarks/bench_ufunc.py +++ b/benchmarks/benchmarks/bench_ufunc.py @@ -150,3 +150,50 @@ class Scalar(Benchmark): def time_add_scalar_conv_complex(self): (self.y + self.z) + + +class ArgParsing(Benchmark): + # In order to benchmark the speed of argument parsing, all but the + # out arguments are chosen such that they have no effect on the + # calculation. In particular, subok=True and where=True are + # defaults, and the dtype is the correct one (the latter will + # still have some effect on the search for the correct inner loop). + x = np.array(1.) + y = np.array(2.) + out = np.array(3.) + param_names = ['arg_kwarg'] + params = [[ + ((x, y), dict()), + ((x, y, out), dict()), + ((x, y), dict(out=out)), + ((x, y), dict(out=(out,))), + ((x, y), dict(out=out, subok=True, where=True)), + ((x, y), dict(subok=True)), + ((x, y), dict(subok=True, where=True)), + ((x, y, out), dict(subok=True, where=True)) + ]] + + def time_add_arg_parsing(self, arg_kwarg): + np.add(*arg_kwarg[0], **arg_kwarg[1]) + + +class ArgParsingReduce(Benchmark): + # In order to benchmark the speed of argument parsing, all but the + # out arguments are chosen such that they have minimal effect on the + # calculation. + a = np.arange(2.) + out = np.array(0.) + param_names = ['arg_kwarg'] + params = [[ + ((a,), dict()), + ((a, 0), dict()), + ((a,), dict(axis=0)), + ((a, 0, None), dict()), + ((a,), dict(axis=0, dtype=None)), + ((a, 0, None, out), dict()), + ((a,), dict(axis=0, dtype=None, out=out)), + ((a,), dict(out=out)) + ]] + + def time_add_reduce_arg_parsing(self, arg_kwarg): + np.add.reduce(*arg_kwarg[0], **arg_kwarg[1]) |