Skip to content

Commit

Permalink
BENCH: split out slow setup method in bench_shape_base.Block
Browse files Browse the repository at this point in the history
The setup for bench_shape_base.Block.time_3d takes 0.5sec -- split it
out to avoid slowing down the other Block benchmarks.
  • Loading branch information
pv committed Sep 4, 2018
1 parent 332da04 commit a798ec7
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions benchmarks/benchmarks/bench_shape_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,6 @@ def setup(self, n):
self.six = 6 * np.ones(5 * n)
self.zero = np.zeros((2 * n, 6 * n))

self.a000 = np.ones((2 * n, 2 * n, 2 * n), int) * 1

self.a100 = np.ones((3 * n, 2 * n, 2 * n), int) * 2
self.a010 = np.ones((2 * n, 3 * n, 2 * n), int) * 3
self.a001 = np.ones((2 * n, 2 * n, 3 * n), int) * 4

self.a011 = np.ones((2 * n, 3 * n, 3 * n), int) * 5
self.a101 = np.ones((3 * n, 2 * n, 3 * n), int) * 6
self.a110 = np.ones((3 * n, 3 * n, 2 * n), int) * 7

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

def time_block_simple_row_wise(self, n):
np.block([self.a_2d, self.b_2d])

Expand Down Expand Up @@ -72,6 +60,29 @@ def time_nested(self, n):
[self.zero]
])

def time_no_lists(self, n):
np.block(1)
np.block(np.eye(3 * n))


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

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

self.a100 = np.ones((3 * n, 2 * n, 2 * n), int) * 2
self.a010 = np.ones((2 * n, 3 * n, 2 * n), int) * 3
self.a001 = np.ones((2 * n, 2 * n, 3 * n), int) * 4

self.a011 = np.ones((2 * n, 3 * n, 3 * n), int) * 5
self.a101 = np.ones((3 * n, 2 * n, 3 * n), int) * 6
self.a110 = np.ones((3 * n, 3 * n, 2 * n), int) * 7

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

def time_3d(self, n):
np.block([
[
Expand All @@ -84,6 +95,5 @@ def time_3d(self, n):
]
])

def time_no_lists(self, n):
np.block(1)
np.block(np.eye(3 * n))
# Retain old benchmark name for backward compat
time_3d.benchmark_name = "bench_shape_base.Block.time_3d"

0 comments on commit a798ec7

Please sign in to comment.