diff options
author | Matti Picus <matti.picus@gmail.com> | 2020-01-07 21:24:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-07 21:24:13 +0200 |
commit | a524490123ed91e91d2b24409f6a7bbf8b8df728 (patch) | |
tree | e88c879868afbbf5001ecff54731c050ddb5eb38 /benchmarks | |
parent | 4ff972604c0f524abc7f10a3af59ce719b3025b4 (diff) | |
parent | ad1dd9066f04f0dda10a1c991480ba506d53676a (diff) | |
download | numpy-a524490123ed91e91d2b24409f6a7bbf8b8df728.tar.gz |
Merge pull request #15278 from seberg/bench-small-array-coercion
BENCH: Add benchmark for small array coercions
Diffstat (limited to 'benchmarks')
-rw-r--r-- | benchmarks/benchmarks/bench_array_coercion.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/benchmarks/benchmarks/bench_array_coercion.py b/benchmarks/benchmarks/bench_array_coercion.py new file mode 100644 index 000000000..2bae4c002 --- /dev/null +++ b/benchmarks/benchmarks/bench_array_coercion.py @@ -0,0 +1,57 @@ +from __future__ import absolute_import, division, print_function + +from .common import Benchmark + +import numpy as np + + +class ArrayCoercionSmall(Benchmark): + # More detailed benchmarks for array coercion, + # some basic benchmarks are in `bench_core.py`. + params = [[range(3), [1], 1, np.array([5], dtype=np.int64), np.int64(5)]] + param_names = ['array_like'] + int64 = np.dtype(np.int64) + + def time_array_invalid_kwarg(self, array_like): + try: + np.array(array_like, ndmin="not-integer") + except TypeError: + pass + + def time_array(self, array_like): + np.array(array_like) + + def time_array_dtype_not_kwargs(self, array_like): + np.array(array_like, self.int64) + + def time_array_no_copy(self, array_like): + np.array(array_like, copy=False) + + def time_array_subok(self, array_like): + np.array(array_like, subok=True) + + def time_array_all_kwargs(self, array_like): + np.array(array_like, dtype=self.int64, copy=False, order="F", + subok=False, ndmin=2) + + def time_asarray(self, array_like): + np.asarray(array_like) + + def time_asarray_dtype(self, array_like): + np.array(array_like, dtype=self.int64) + + def time_asarray_dtype(self, array_like): + np.array(array_like, dtype=self.int64, order="F") + + def time_asanyarray(self, array_like): + np.asarray(array_like) + + def time_asanyarray_dtype(self, array_like): + np.array(array_like, dtype=self.int64) + + def time_asanyarray_dtype(self, array_like): + np.array(array_like, dtype=self.int64, order="F") + + def time_ascontiguousarray(self, array_like): + np.ascontiguousarray(array_like) + |