Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/schurhammer/gleamy_bench
A library for benchmarking gleam code.
https://github.com/schurhammer/gleamy_bench
Last synced: 3 months ago
JSON representation
A library for benchmarking gleam code.
- Host: GitHub
- URL: https://github.com/schurhammer/gleamy_bench
- Owner: schurhammer
- License: apache-2.0
- Created: 2023-11-01T03:40:04.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-16T07:49:52.000Z (9 months ago)
- Last Synced: 2024-04-26T03:20:51.965Z (7 months ago)
- Language: Gleam
- Size: 21.5 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-gleam - gleamy_bench - [📚](https://hexdocs.pm/gleamy_bench/) - A library for benchmarking gleam code. (Packages / Benchmarking)
README
# gleamy_bench
[![Package Version](https://img.shields.io/hexpm/v/gleamy_bench)](https://hex.pm/packages/gleamy_bench)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/gleamy_bench/)A library for benchmarking gleam code.
# How To
```gleam
import gleamy/bench// ...
bench.run(
[
bench.Input("pre-sorted list", list.range(1, 100_000)),
bench.Input("reversed list", list.reverse(list.range(1, 100_000))),
],
[bench.Function("list.sort()", sort_int)],
[bench.Duration(1000), bench.Warmup(100)],
)
|> bench.table([bench.IPS, bench.Min, bench.P(99)])
|> io.println()
```A benchmark is defined by giving a list of inputs and a list of functions to run on those inputs. Each input + function combination will be timed.
The given inputs should all be the same type, and the functions should all accept that type as the only argument.
The `run` function actually runs the benchmark and collects the results. It also accepts a list of options to change default behaviour, for example `Duration(1000)` is used to change how long each function is run repeatedly when collecting results (in milliseconds). This list is optional and can be empty if you have no need to change the defaults.
The `table` function makes a table out of the results. You can choose the list of statistics you would like to include in the table.
The output for this example looks like the following.
```
Input Function IPS Min P99
pre-sorted list list.sort() 37.8532 22.4190 31.3593
reversed list list.sort() 34.0101 27.0734 31.0618
```## Contributing
Suggestions and pull requests are welcome!
## Installation
This package can be added to your Gleam project:
```sh
gleam add gleamy_bench
```and its documentation can be found at .