Skip to content

Commit

Permalink
skeleton for benchmarking workflow (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfmig committed Oct 9, 2023
1 parent bb7881c commit a64dac6
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 98 deletions.
106 changes: 106 additions & 0 deletions benchmarks/cellfinder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import shutil

from brainglobe_workflows.cellfinder.cellfinder_main import (
run_workflow_from_cellfinder_run,
)
from brainglobe_workflows.cellfinder.cellfinder_main import (
setup as setup_workflow,
)


class TimeBenchmark:
"""
Base class with sensible options
See https://asv.readthedocs.io/en/stable/benchmarks.html#benchmark-attributes
The sample_time, number, repeat, and timer attributes can be adjusted in
the setup() routine, which can be useful for parameterized benchmarks
Other attributes for time benchmarks not specified in this class:
- number: the number of iterations in each sample. If number is specified,
sample_time is ignored. Note that setup and teardown are not run between
iterations: setup runs first, then the timed benchmark routine is called
number times, and after that teardown runs.
- timer: timeit.default_timer by default
Notes about some of the default attributes for time benchmarks:
- warmup_time: asv will spend this time (in seconds) in calling the
benchmarked function repeatedly, before starting to run the
actual benchmark
- repeat: when not provided (repeat set to 0):
- if rounds==1 the default is
(min_repeat, max_repeat, max_time) = (1, 10, 20.0),
- if rounds != 1 the default is
(min_repeat, max_repeat, max_time) = (1, 5, 10.0)
- sample_time: `number` is determined so that each sample takes
approx sample_time=10ms
"""

timeout = 600 # default: 60 s
version = None # default: None (i.e. hash of source code)
warmup_time = 0.1 # default:0.1;
rounds = 2 # default:2
repeat = 0 # default: 0
sample_time = 0.01 # default: 10 ms = 0.01 s;
min_run_count = 2 # default:2

# @classmethod ---> this was to reuse this setup fn for other benchmarls
def setup_cache(
self,
): # ---> cache so that we dont download data several times?
# monkeypatch command line arguments
# run setup
cfg = setup_workflow(
[
"--config",
"/Users/sofia/Documents_local/project_BrainGlobe_workflows/"
"brainglobe-workflows/brainglobe_workflows/cellfinder/default_config.json",
]
)
self.cfg = cfg

def teardown(self):
shutil.rmtree(self.cfg.install_path)


class TimeFullWorkflow(TimeBenchmark):
def time_workflow_from_cellfinder_run(self):
run_workflow_from_cellfinder_run(self.cfg)


# class TimeReadInputDask(TimeBenchmark):
# def time_read_signal_w_dask(self):
# read_with_dask(self.cfg.signal_parent_dir)

# def time_read_background_w_dask(self):
# read_with_dask(self.cfg.background_parent_dir)


# class TimeCellfinderRun(TimeBenchmark):
# def setup(self):
# TimeBenchmark.setup()
# self.signal_array = read_with_dask(self.cfg.signal_parent_dir)
# self.background_array = read_with_dask(
# self.cfg.background_parent_dir
# )

# def time_cellfinder_run(self):
# cellfinder_run(
# self.signal_array, self.background_array, self.cfg.voxel_sizes
# )


# class TimeSaveCells(TimeBenchmark):
# def setup(self):
# TimeBenchmark.setup()
# signal_array = read_with_dask(self.cfg.signal_parent_dir)
# background_array = read_with_dask(self.cfg.background_parent_dir)

# self.detected_cells = cellfinder_run(
# signal_array, background_array, self.cfg.voxel_sizes
# )

# def time_save_cells(self):
# save_cells(self.detected_cells, self.cfg.detected_cells_filepath)
Empty file removed benchmarks/cellfinder/__init__.py
Empty file.
98 changes: 0 additions & 98 deletions benchmarks/cellfinder/workflows.py

This file was deleted.

23 changes: 23 additions & 0 deletions benchmarks/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class TimeSuite:
"""
An example benchmark that times the performance of various kinds
of iterating over dictionaries in Python.
"""

def setup(self):
self.d = {}
for x in range(500):
self.d[x] = None

def time_keys(self):
for key in self.d.keys():
pass

def time_values(self):
for value in self.d.values():
pass

def time_range(self):
d = self.d
for key in range(500):
d[key]

0 comments on commit a64dac6

Please sign in to comment.