E606 BENCH: Add basic benchmarks for scalar indexing and assignment by seberg · Pull Request #16786 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions benchmarks/benchmarks/bench_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,36 @@ def time_op(self, indexes, sel, op):
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()
Expand Down
0