File: benchmark_util.py

package info (click to toggle)
skimage 0.25.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,720 kB
  • sloc: python: 60,007; cpp: 2,592; ansic: 1,591; xml: 1,342; javascript: 1,267; makefile: 168; sh: 20
file content (27 lines) | stat: -rw-r--r-- 847 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# See "Writing benchmarks" in the asv docs for more information.
# https://asv.readthedocs.io/en/latest/writing_benchmarks.html
import numpy as np
from skimage import util


class NoiseSuite:
    """Benchmark for noise routines in scikit-image."""

    params = ([0.0, 0.50, 1.0], [0.0, 0.50, 1.0])

    def setup(self, *_):
        self.image = np.zeros((5000, 5000))

    def peakmem_salt_and_pepper(self, amount, salt_vs_pepper):
        self._make_salt_and_pepper_noise(amount, salt_vs_pepper)

    def time_salt_and_pepper(self, amount, salt_vs_pepper):
        self._make_salt_and_pepper_noise(amount, salt_vs_pepper)

    def _make_salt_and_pepper_noise(self, amount, salt_vs_pepper):
        util.random_noise(
            self.image,
            mode="s&p",
            amount=amount,
            salt_vs_pepper=salt_vs_pepper,
        )