forked from scikit-image/scikit-image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_segmentation.py
40 lines (31 loc) · 1.38 KB
/
benchmark_segmentation.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
# See "Writing benchmarks" in the asv docs for more information.
import numpy as np
from skimage import segmentation
class SegmentationSuite:
"""Benchmark for segmentation routines in scikit-image."""
def setup(self):
self.image = np.random.random((400, 400, 100))
self.image[:200, :200, :] += 1
self.image[300:, 300:, :] += 0.5
self.msk = np.zeros((400, 400, 100))
self.msk[10:-10, 10:-10, 10:-10] = 1
def time_slic_basic(self):
segmentation.slic(self.image, enforce_connectivity=False)
def time_mask_slic(self):
segmentation.slic(self.image, enforce_connectivity=False,
mask=self.msk)
def peakmem_setup(self):
"""peakmem includes the memory used by setup.
Peakmem benchmarks measure the maximum amount of RAM used by a
function. However, this maximum also includes the memory used
by ``setup`` (as of asv 0.2.1; see [1]_)
Measuring an empty peakmem function might allow us to disambiguate
between the memory used by setup and the memory used by slic (see
``peakmem_slic_basic``, below).
References
----------
.. [1]: https://asv.readthedocs.io/en/stable/writing_benchmarks.html#peak-memory
"""
pass
def peakmem_slic_basic(self):
segmentation.slic(self.image, enforce_connectivity=False)