diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2020-01-06 15:50:54 -0600 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2020-01-07 10:42:26 -0600 |
commit | ad1dd9066f04f0dda10a1c991480ba506d53676a (patch) | |
tree | a58678c3d182cfcb796d3d0a9b4615fd895c5656 /benchmarks | |
parent | 33976ed1fb030e45e6f8a3e43d830799cfc0b5d2 (diff) | |
download | numpy-ad1dd9066f04f0dda10a1c991480ba506d53676a.tar.gz |
BENCH: Add benchmark for small array coercions
Note that since the benchmarks are so fast, the actual results
are diluted behind one more python function call.
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) + |