summaryrefslogtreecommitdiff
path: root/benchmarks
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2018-06-29 20:58:52 -0700
committerEric Wieser <wieser.eric@gmail.com>2018-06-29 21:27:23 -0700
commite238112098ede67be0c7f7ba0e44b6b14224e7eb (patch)
treebff53ce8d67855ec6ca3586f2ce536453fdcbd5b /benchmarks
parentb62c226f6a0de294b4ab3b190068c808a85f85f6 (diff)
downloadnumpy-e238112098ede67be0c7f7ba0e44b6b14224e7eb.tar.gz
MAINT: Produce a more readable repr of argument packs in benchmark
Follow up to gh-11453
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/benchmarks/bench_ufunc.py52
1 files changed, 32 insertions, 20 deletions
diff --git a/benchmarks/benchmarks/bench_ufunc.py b/benchmarks/benchmarks/bench_ufunc.py
index 5d5eae251..a7e385f70 100644
--- a/benchmarks/benchmarks/bench_ufunc.py
+++ b/benchmarks/benchmarks/bench_ufunc.py
@@ -152,6 +152,18 @@ class Scalar(Benchmark):
(self.y + self.z)
+class ArgPack(object):
+ __slots__ = ['args', 'kwargs']
+ def __init__(self, *args, **kwargs):
+ self.args = args
+ self.kwargs = kwargs
+ def __repr__(self):
+ return '({})'.format(', '.join(
+ [repr(a) for a in self.args] +
+ ['{}={}'.format(k, repr(v)) for k, v in self.kwargs.items()]
+ ))
+
+
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
@@ -163,18 +175,18 @@ class ArgParsing(Benchmark):
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))
+ ArgPack(x, y),
+ ArgPack(x, y, out),
+ ArgPack(x, y, out=out),
+ ArgPack(x, y, out=(out,)),
+ ArgPack(x, y, out=out, subok=True, where=True),
+ ArgPack(x, y, subok=True),
+ ArgPack(x, y, subok=True, where=True),
+ ArgPack(x, y, out, subok=True, where=True)
]]
- def time_add_arg_parsing(self, arg_kwarg):
- np.add(*arg_kwarg[0], **arg_kwarg[1])
+ def time_add_arg_parsing(self, arg_pack):
+ np.add(*arg_pack.args, **arg_pack.kwargs)
class ArgParsingReduce(Benchmark):
@@ -185,15 +197,15 @@ class ArgParsingReduce(Benchmark):
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))
+ ArgPack(a,),
+ ArgPack(a, 0),
+ ArgPack(a, axis=0),
+ ArgPack(a, 0, None),
+ ArgPack(a, axis=0, dtype=None),
+ ArgPack(a, 0, None, out),
+ ArgPack(a, axis=0, dtype=None, out=out),
+ ArgPack(a, out=out)
]]
- def time_add_reduce_arg_parsing(self, arg_kwarg):
- np.add.reduce(*arg_kwarg[0], **arg_kwarg[1])
+ def time_add_reduce_arg_parsing(self, arg_pack):
+ np.add.reduce(*arg_pack.args, **arg_pack.kwargs)