Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

asv benchmarks for imports and tools modules #184

Merged
merged 36 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2c5a65c
notebook w typical pipeline
sfmig Jun 22, 2023
2a4c729
notes on writing benchmarks
sfmig Jun 26, 2023
9879ca6
pipeline notebook
sfmig Jun 26, 2023
fad8b8a
update gitignore
sfmig Jun 26, 2023
4603bcb
add imports benchmarks
sfmig Jun 26, 2023
67faa02
basic benchmark for reading with dask
sfmig Jun 26, 2023
fb8ebe9
parametrise dask benchmark
sfmig Jun 26, 2023
a00131e
add tiff benchmark and refactor
sfmig Jun 28, 2023
9bc0046
fix build command to use pyproject correctly
sfmig Jun 28, 2023
2bf4c5a
black formatting to IO benchmarks
sfmig Jun 29, 2023
336be4c
prep benchmarks pending teardown
sfmig Jun 29, 2023
a2b200e
remove voxel_size from IO and refactor. change precommit config to sk…
sfmig Jun 29, 2023
3f3a344
remove list comprehension
sfmig Jun 29, 2023
d20a97b
add benchmarks imports
sfmig Jun 29, 2023
80f12a0
remove initial templates
sfmig Jun 29, 2023
bfc7383
add init to benchmarks
sfmig Jun 29, 2023
589ffce
add readme and comments to asv config
sfmig Jun 30, 2023
febb776
add teardown function to prep benchmarks
sfmig Jun 30, 2023
2e35a8a
add comment for review
sfmig Jun 30, 2023
ebd57fb
Merge branch 'main' into smg/basic-asv-benchmark
sfmig Jun 30, 2023
382a285
add cellfinder_core.tools.prep mypy fix
sfmig Jun 30, 2023
357725f
replace imlib by brainglobe_utils
sfmig Jun 30, 2023
43fe398
small additions to readme
sfmig Jun 30, 2023
f6b8f08
move cellfinder_core.tool.prep to ignore imports section
sfmig Jun 30, 2023
2051c4a
remove notebook
sfmig Jun 30, 2023
d0ce539
increase timeout
sfmig Jun 30, 2023
70dffb3
small additions and format edits to the readme
sfmig Jul 20, 2023
701a135
exclude benchmarks from manifest
sfmig Jul 20, 2023
8d3ed4b
small additions to the readme
sfmig Jul 20, 2023
150eda7
reduce readme to basic commands
sfmig Jul 20, 2023
333155e
fixes to IO benchmarks from review discussions
sfmig Jul 21, 2023
45510da
fix typo
sfmig Jul 21, 2023
397aeb3
Apply Will's suggestions from code review
sfmig Jul 21, 2023
0ddd6b7
Merge branch 'smg/basic-asv-benchmark' of https://github.com/brainglo…
sfmig Jul 21, 2023
a5fcee1
change install path. remove TODOs. increase default timeout further
sfmig Jul 21, 2023
9e1d4c1
Merge branch 'main' into smg/basic-asv-benchmark
sfmig Jul 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
prune tests/data
include README.md
include LICENSE
include pyproject.toml

exclude *.yml
exclude *.yaml
exclude tox.ini
exclude CHANGELOG.md

graft src

prune benchmarks
prune tests

exclude cellfinder-core/benchmarks/*
sfmig marked this conversation as resolved.
Show resolved Hide resolved
124 changes: 2 additions & 122 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pip install asv

`asv` works roughly as follows:
1. It creates a virtual environment (as defined in the config)
2. It installs the software package version of a specific commit
2. It installs the software package version of a specific commit (or of a local commit)
3. It times the benchmarking tests and saves the results to json files
4. The json files are 'published' into an html dir
5. The html dir can be visualised in a static website
Expand All @@ -31,129 +31,9 @@ To collate the benchmarks' results into a viewable website:
```
$ asv publish
```
This will create a tree of files in the `html` directory, but this cannot be viewed directly from the local filesystem, so we need to put them in a static site. `asv publish` also detects satistically significant decreases of performance, the results can be inspected in the 'Regression' tab of the static site (more on that on the next section).
This will create a tree of files in the `html` directory, but this cannot be viewed directly from the local filesystem, so we need to put them in a static site. `asv publish` also detects satistically significant decreases of performance, the results can be inspected in the 'Regression' tab of the static site.

To visualise the results in a static site:
```
$ asv preview
```
To share the website on the internet, put the files in the `html` directory on any webserver that can serve static content (e.g. GitHub pages).

To put the results in the `gh-pages` branch and push them to GitHub:
```
$asv gh-pages
```

## Managing the results

To remove benchmarks from the database, for example, for a specific commit:

```
$ asv rm commit_hash=a802047be
```
See more options in the [documentation](https://asv.readthedocs.io/en/stable/using.html#managing-the-results-database).

This will remove the selected results from the files in the `results` directory. To update the results in the static site, remember to run `publish` again!


To compare the results of running the benchmarks on two commits:
```
$ asv compare 88fbbc33 827f322b
```

## Automatically detecting performance regressions



## Other handy commands
To update the machine information
```
$ asv machine
```

To display results from previous runs on the command line
```
$ asv show
```

To use binary search to find a commit within the benchmarked range that produced a large regression
```
$ asv check
$ asv find
```

To check the validity of written benchmarks
```
$ asv check
```


## Development notes:
In development, the following flags to `asv run` are often useful:
- `--bench`: to specify a subset of benchmarks (e.g., `tools.prep.PrepTF`). Regexp can be used.
- `--dry-run`: will not write results to disk
- `--quick`: will only run one repetition, and no results to disk
- `--show-stderr`: will print out stderr
- `--verbose`: provides further info on intermediate steps
- `--python=same`: runs the benchmarks in the same environment that `asv` was launched from

E.g.:
```
asv run --bench bench tools.prep.PrepTF --dry-run --show-stderr --quick
```

### Running benchmarks against a local commit
To run the benchmarks against a local commit (for example, if you are trying to improve the performance of the code), you need to edit the `repo` field in the asv config file `asv.conf.json`.

To use the upstream repository, use:
```
"repo": "https://github.com/brainglobe/cellfinder-core.git",
```

To use the local repository, use:
```
"repo": "..",
```

### setup and setup_cache

Setup includes initialisation bits that should not be included
in the timing of the benchmark.

It can be added as:
- a method of a class, or
- an attribute of a free function, or
- a module-level setup function (run for every benchmark in the
module, prior to any function-specific setup)

If setup raises `NotImplementedError`, the benchmark is skipped

`setup_cache` only performs the setup calculation once
(for each benchmark and each repeat) and caches the
result to disk. This may be useful if the setup is
expensive.

A separate cache is used for each environment and each commit.
The cache is thrown out between benchmark runs.

There are two options to persist the data for the benchmarks:
- `setup_cache` returns a data structure, which asv pickles to disk,
and then loads and passes as first arg to each benchmark (not
automagically tho), or
- `setup_cache` saves files to the cwd (which is a temp dir managed by
asv), which are then explicitly loaded in each benchmark. Recomm
practice is to actually read the data in a `setup` fn, so that
loading time is not part of the timing

### Check benchmarks
To check the validity of written benchmarks
```
$ asv check
```


----
## References
- [astropy-benchmarks repository](https://github.com/astropy/astropy-benchmarks/tree/main)
- [numpy benchmarks](https://github.com/numpy/numpy/tree/main/benchmarks/benchmarks)
- [asv documentation](https://asv.readthedocs.io/en/stable/index.html)