8000 Merge pull request #11965 from hmaarrfk/bench_concatenate · numpy/numpy@8d7b7b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d7b7b5

Browse files
authored
Merge pull request #11965 from hmaarrfk/bench_concatenate
BENCH: Add a benchmark comparing block to copy in the 3D case
2 parents a2fb23a + f37b0c6 commit 8d7b7b5

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

benchmarks/benchmarks/bench_shape_base.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,18 @@ def time_block2d(self, shape, dtype, n_chunks):
8888

8989

9090
class Block3D(Benchmark):
91-
params = [1, 10, 100]
92-
param_names = ['size']
93-
94-
def setup(self, n):
91+
"""This benchmark concatenates an array of size ``(5n)^3``"""
92+
# Having copy as a `mode` of the block3D
93+
# allows us to directly compare the benchmark of block
94+
# to that of a direct memory copy into new buffers with
95+
# the ASV framework.
96+
# block and copy will be plotted on the same graph
97+
# as opposed to being displayed as separate benchmarks
98+
params = [[1, 10, 100],
99+
['block', 'copy']]
100+
param_names = ['n', 'mode']
101+
102+
def setup(self, n, mode):
95103
# Slow setup method: hence separated from the others above
96104
self.a000 = np.ones((2 * n, 2 * n, 2 * n), int) * 1
97105

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

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

108-
def time_3d(self, n):
109-
np.block([
116+
self.block = [
110117
[
111118
[self.a000, self.a001],
112119
[self.a010, self.a011],
@@ -115,7 +122,17 @@ def time_3d(self, n):
115122
[self.a100, self.a101],
116123
[self.a110, self.a111],
117124
]
118-
])
125+
]
126+
self.arr_list = [a
127+
for two_d in self.block
128+
for one_d in two_d
129+
for a in one_d]
130+
131+
def time_3d(self, n, mode):
132+
if mode == 'block':
133+
np.block(self.block)
134+
else: # mode == 'copy'
135+
[arr.copy() for arr in self.arr_list]
119136

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

0 commit comments

Comments
 (0)
0