diff options
author | Mark Harfouche <mark.harfouche@gmail.com> | 2018-09-16 14:53:27 -0400 |
---|---|---|
committer | mattip <matti.picus@gmail.com> | 2018-10-19 11:11:36 +0300 |
commit | f37b0c6fadb9dc0b4134ebe844645d44f78c146d (patch) | |
tree | 2a52b76a65d08a633b58a67ae34e5ccc9eaf1e46 /benchmarks | |
parent | 57100ac2a776f86bad868f9f0b4b9d948a4033dc (diff) | |
download | numpy-f37b0c6fadb9dc0b4134ebe844645d44f78c146d.tar.gz |
ENH: Add a benchmark comparing block to copy in the 3D case
Diffstat (limited to 'benchmarks')
-rw-r--r-- | benchmarks/benchmarks/bench_shape_base.py | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/benchmarks/benchmarks/bench_shape_base.py b/benchmarks/benchmarks/bench_shape_base.py index e48ea0adb..187b923cd 100644 --- a/benchmarks/benchmarks/bench_shape_base.py +++ b/benchmarks/benchmarks/bench_shape_base.py @@ -88,10 +88,18 @@ class Block2D(Benchmark): 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 @@ -105,8 +113,7 @@ class Block3D(Benchmark): 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], @@ -115,7 +122,17 @@ class Block3D(Benchmark): [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" |