From 6ade16ee3f9cc0dd4f8486da6c247720f14c4e1e Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sat, 15 Sep 2018 16:01:59 -0400 Subject: Force pagefaults on other benchmarks too --- benchmarks/benchmarks/bench_ma.py | 4 +++- benchmarks/benchmarks/bench_reduce.py | 6 ++++-- benchmarks/benchmarks/bench_shape_base.py | 8 ++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) (limited to 'benchmarks') diff --git a/benchmarks/benchmarks/bench_ma.py b/benchmarks/benchmarks/bench_ma.py index d313f01dc..aff78df0a 100644 --- a/benchmarks/benchmarks/bench_ma.py +++ b/benchmarks/benchmarks/bench_ma.py @@ -89,7 +89,9 @@ class Concatenate(Benchmark): ] def setup(self, mode, n): - normal = np.zeros((n, n), int) + # avoid np.zeros's lazy allocation that cause page faults during benchmark. + # np.fill will cause pagefaults to happen during setup. + normal = np.full((n, n), 0, int) unmasked = np.ma.zeros((n, n), int) masked = np.ma.array(normal, mask=True) diff --git a/benchmarks/benchmarks/bench_reduce.py b/benchmarks/benchmarks/bench_reduce.py index 353eb980c..ffc148cd2 100644 --- a/benchmarks/benchmarks/bench_reduce.py +++ b/benchmarks/benchmarks/bench_reduce.py @@ -29,8 +29,10 @@ class AddReduceSeparate(Benchmark): class AnyAll(Benchmark): def setup(self): - self.zeros = np.zeros(100000, bool) - self.ones = np.ones(100000, bool) + # avoid np.zeros's lazy allocation that would + # cause page faults during benchmark + self.zeros = np.full(100000, 0, bool) + self.ones = np.full(100000, 0, bool) def time_all_fast(self): self.zeros.all() diff --git a/benchmarks/benchmarks/bench_shape_base.py b/benchmarks/benchmarks/bench_shape_base.py index b05ea8263..6edad2ea3 100644 --- a/benchmarks/benchmarks/bench_shape_base.py +++ b/benchmarks/benchmarks/bench_shape_base.py @@ -23,7 +23,9 @@ class Block(Benchmark): self.four_1d = np.ones(6 * n) self.five_0d = np.ones(1 * n) self.six_1d = np.ones(5 * n) - self.zero_2d = np.zeros((2 * n, 6 * n)) + # avoid np.zeros's lazy allocation that might cause + # page faults during benchmark + self.zero_2d = np.full((2 * n, 6 * n), 0) self.one = np.ones(3 * n) self.two = 2 * np.ones((3, 3 * n)) @@ -31,7 +33,9 @@ class Block(Benchmark): self.four = 4 * np.ones(3 * n) self.five = 5 * np.ones(1 * n) self.six = 6 * np.ones(5 * n) - self.zero = np.zeros((2 * n, 6 * n)) + # avoid np.zeros's lazy allocation that might cause + # page faults during benchmark + self.zero = np.full((2 * n, 6 * n), 0) def time_block_simple_row_wise(self, n): np.block([self.a_2d, self.b_2d]) -- cgit v1.2.1