8000 BENCH: Add a benchmark comparing block to copy in the 3D case by hmaarrfk · Pull Request #11965 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BENCH: Add a benchmark comparing block to copy in the 3D case #11965

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 1 commit into from
Oct 19, 2018
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
ENH: Add a benchmark comparing block to copy in the 3D case
  • Loading branch information
hmaarrfk authored and mattip committed Oct 19, 2018
commit f37b0c6fadb9dc0b4134ebe844645d44f78c146d
31 changes: 24 additions & 7 deletions benchmarks/benchmarks/bench_shape_base.py
8000
Original file line numberDiff line number Diff line change
Expand Up @@ -88,10 +88,18 @@ def time_block2d(self, shape, dtype, n_chunks):


class Block3D(Benchmark):
params = [1, 10, 100]
param_names = ['size']

def setup(self, n):
"""This benchmark concatenates an array of size ``(5n)^3``"""
# Having copy as a `mode` of the block3D
# allows us to directly compare the benchmark of block
# to that of a direct memory copy into new buffers with
# the ASV framework.
# block and copy will be plotted on the same graph
# as opposed to being displayed as separate benchmarks
params = [[1, 10, 100],
['block', 'copy']]
param_names = ['n', 'mode']

def setup(self, n, mode):
# Slow setup method: hence separated from the others above
self.a000 = np.ones((2 * n, 2 * n, 2 * n), int) * 1

Expand All @@ -105,8 +113,7 @@ def setup(self, n):

self.a111 = np.ones((3 * n, 3 * n, 3 * n), int) * 8

def time_3d(self, n):
np.block([
self.block = [
[
[self.a000, self.a001],
[self.a010, self.a011],
Expand All @@ -115,7 +122,17 @@ def time_3d(self, n):
[self.a100, self.a101],
[self.a110, self.a111],
]
])
]
self.arr_list = [a
for two_d in self.block
for one_d in two_d
for a in one_d]

def time_3d(self, n, mode):
if mode == 'block':
np.block(self.block)
else: # mode == 'copy'
[arr.copy() for arr in self.arr_list]

# Retain old benchmark name for backward compat
time_3d.benchmark_name = "bench_shape_base.Block.time_3d"
0