10000 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

BENCH: Add basic benchmarks for scalar indexing and assignment #16786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 9, 2020
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
7B51
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