8000 BENCH: use initialized memory for count_nonzero benchmark · juliantaylor/numpy@6a4858c · GitHub
  • [go: up one dir, main page]

    Skip to content

    Commit 6a4858c

    Browse files
    committed
    BENCH: use initialized memory for count_nonzero benchmark
    For the bool case uninitialized memory can randomly go into the slow path handling values different than 0 or 1.
    1 parent a7ed83f commit 6a4858c

    File tree

    1 file changed

    +2
    -2
    lines changed

    1 file changed

    +2
    -2
    lines changed

    benchmarks/benchmarks/bench_core.py

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -137,8 +137,8 @@ class CountNonzero(Benchmark):
    137137
    ]
    138138

    139139
    def setup(self, numaxes, size, dtype):
    140-
    self.x = np.empty(shape=(
    141-
    numaxes, size), dtype=dtype)
    140+
    self.x = np.arange(numaxes * size).reshape(numaxes, size)
    141+
    self.x = (self.x % 3).astype(dtype)
    142142

    143143
    def time_count_nonzero(self, numaxes, size, dtype):
    144144
    np.count_nonzero(self.x)

    0 commit comments

    Comments
     (0)
    0