Skip to content

Commit

Permalink
describe pytest-benchmark support in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Nov 17, 2019
1 parent 18c82f2 commit 895f92f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 9 deletions.
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This action currently supports
- [`cargo bench`][cargo-bench] for Rust projects
- `go test -bench` for Go projects
- [benchmark.js][benchmarkjs] for JavaScript/TypeScript projects
- [pytest-benchmark][] for Python projects with [pytest][]

Multiple languages in the same repository is supported for polyglot projects.

Expand All @@ -25,6 +26,7 @@ are in [.github/workflows/](./.github/workflows) directory. Workflow actions are
- Rust: [![Rust Example Workflow][rust-badge]](https://github.com/rhysd/github-action-benchmark/actions?query=workflow%3A%22Rust+Example%22)
- Go: [![Go Example Workflow][go-badge]](https://github.com/rhysd/github-action-benchmark/actions?query=workflow%3A%22Go+Example%22)
- JavaScript: [![JavaScript Example Workflow][benchmarkjs-badge]](https://github.com/rhysd/github-action-benchmark/actions?query=workflow%3A%22Benchmark.js+Example%22)
- Python (pytest-benchmark): [![Pytest Example Workflow][TODO]](TODO)

All benchmark charts from above workflows are gathered in GitHub pages:

Expand Down Expand Up @@ -162,22 +164,23 @@ Please read `README.md` files at each example directory.
- [`cargo bench` for Rust projects](./examples/rust/README.md)
- [`go test` for Go projects](./examples/go/README.md)
- [Benchmark.js for JavaScript/TypeScript projects](./examples/benchmarkjs/README.md)
- [pytest-benchmark for Python projects with pytest](./examples/pytest/README.md)

These examples are run in workflows of this repository as described in 'Examples' section above.

### Action inputs

Input definitions are written in [action.yml](./action.yml).

| Name | Description | Type | Required | Default |
|---------------------------|------------------------------------------------------------------------------------------------------|-------------------------------------------|----------|---------------|
| `name` | Name of the benchmark. This value must be identical across all benchmarks in your repository. | String | Yes | `"Benchmark"` |
| `tool` | Tool for running benchmark | One of `"cargo"`, `"go"`, `"benchmarkjs"` | Yes | |
| `output-file-path` | Path to file which contains the benchmark output. Relative to repository root | String | Yes | |
| `gh-pages-branch` | Name of your GitHub pages branch | String | Yes | `"gh-pages"` |
| `benchmark-data-dir-path` | Path to directory which contains benchmark files on GitHub pages branch. Relative to repository root | String | Yes | `"dev/bench"` |
| `github-token` | GitHub API token. For public repo, personal access token is necessary. Please see basic usage | String | No | |
| `auto-push` | If set to `true`, this action automatically pushes generated commit to GitHub Pages branch | Boolean | No | `false` |
| Name | Description | Type | Required | Default |
|---------------------------|------------------------------------------------------------------------------------------------------|-------------------------------------------------------|----------|---------------|
| `name` | Name of the benchmark. This value must be identical across all benchmarks in your repository. | String | Yes | `"Benchmark"` |
| `tool` | Tool for running benchmark | One of `"cargo"`, `"go"`, `"benchmarkjs"`, `"pytest"` | Yes | |
| `output-file-path` | Path to file which contains the benchmark output. Relative to repository root | String | Yes | |
| `gh-pages-branch` | Name of your GitHub pages branch | String | Yes | `"gh-pages"` |
| `benchmark-data-dir-path` | Path to directory which contains benchmark files on GitHub pages branch. Relative to repository root | String | Yes | `"dev/bench"` |
| `github-token` | GitHub API token. For public repo, personal access token is necessary. Please see basic usage | String | No | |
| `auto-push` | If set to `true`, this action automatically pushes generated commit to GitHub Pages branch | Boolean | No | `false` |

`name` and `tool` must be specified in workflow at `uses` section of job step.

Expand Down Expand Up @@ -269,3 +272,5 @@ For example, `rhysd/github-action-benchmark@v1` means the latest version of `1.x
[benchmarkjs]: https://benchmarkjs.com/
[gh-pages]: https://pages.github.com/
[examples-page]: https://rhysd.github.io/github-action-benchmark/dev/bench/
[pytest-benchmark]: https://pypi.org/project/pytest-benchmark/
[pytest]: https://pypi.org/project/pytest/
60 changes: 60 additions & 0 deletions examples/pytest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Python example for benchmarking with [pytest-benchmark][tool]
=============================================================

- [Workflow for this example](TODO)
- [Action log of this example](TODO)
- [Benchmark results on GitHub pages](https://rhysd.github.io/github-action-benchmark/dev/bench/)

This directory shows how to use [`github-action-benchmark`](https://github.com/rhysd/github-action-benchmark)
with [pytest-benchmark][tool].

## Run benchmarks

Official documentation for usage of pytest-benchmark:

https://pytest-benchmark.readthedocs.io/en/stable/

Install dependencies with `venv` package using Python3.

```sh
$ python -m venv venv
$ source venv/bin/activate
$ pip install pytest pytest-benchmark
```

Prepare `bench.py` as follows:

e.g.

```python
import pytest

def some_test_case(benchmark):
benchmark(some_func, args)
```

And run benchmarks with `--benchmark-json` in workflow. The JSON file will be an input to
github-action-benchmark.

e.g.

```yaml
- name: Run benchmark
run: pytest bench.py --benchmark-json output.json
```
## Process benchmark results
Store the benchmark results with step using the action. Please set `pytest` to `tool` input.

```yaml
- name: Store benchmark result
uses: rhysd/github-action-benchmark@v1
with:
tool: 'pytest'
output-file-path: output.json
```

Please read ['How to use' section](https://github.com/rhysd/github-action-benchmark#how-to-use) for common usage.

[tool]: https://pypi.org/project/pytest-benchmark/

0 comments on commit 895f92f

Please sign in to comment.