diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2020-07-09 00:17:33 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-09 08:17:33 +0300 |
commit | 86fcce61c9cddbc354ba67b2f818670f5822c688 (patch) | |
tree | 693b03b75e9876fba401b5041e908344a8a6b3c8 /benchmarks | |
parent | 996e6419e44668a6daa28f58efcc0d2c07b3a9da (diff) | |
download | numpy-86fcce61c9cddbc354ba67b2f818670f5822c688.tar.gz |
BENCH: Add basic benchmarks for scalar indexing and assignment (#16786)
* BENCH: Add basic benchmarks for scalar indexing and assignment
Diffstat (limited to 'benchmarks')
-rw-r--r-- | benchmarks/benchmarks/bench_indexing.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/benchmarks/benchmarks/bench_indexing.py b/benchmarks/benchmarks/bench_indexing.py index 9ee0d1fb5..3206392ea 100644 --- a/benchmarks/benchmarks/bench_indexing.py +++ b/benchmarks/benchmarks/bench_indexing.py @@ -31,6 +31,36 @@ class Indexing(Benchmark): self.func() +class ScalarIndexing(Benchmark): + params = [[0, 1, 2]] + param_names = ["ndim"] + + def setup(self, ndim): + self.array = np.ones((5,) * ndim) + + def time_index(self, ndim): + # time indexing. + arr = self.array + indx = (1,) * ndim + for i in range(100): + arr[indx] + + def time_assign(self, ndim): + # time assignment from a python scalar + arr = self.array + indx = (1,) * ndim + for i in range(100): + arr[indx] = 5. + + def time_assign_cast(self, ndim): + # time an assignment which may use a cast operation + arr = self.array + indx = (1,) * ndim + val = np.int16(43) + for i in range(100): + arr[indx] = val + + class IndexingSeparate(Benchmark): def setup(self): self.tmp_dir = mkdtemp() |