bencher
bencher
Bencher is a extension to help gather runtime data on your application. It will report the execution time of all methods in the program. This is very much experimental.
Installation
Add this to your application's shard.yml
:
development_dependencies:
bencher:
github: spoved/bencher.cr
Usage
To get the most out of bencher, you must require it before any other libraries. I also suggest it be wrapped in a compile time flag so it will not be introduced in production or non-test binaries.
{% if flag?(:benchmark) %}
require "bencher"
{% end %}
# Other libraries
require "json"
require "uuid"
Thats it! Simply build with the --release -Dbenchmark
options and on exit, a report of all the method calls and the time it took to execute will be printed to SDTOUT.
If you want to write the report to file, there are a couple ENVs you can set:
env | description | default
---|---|---
BENCHER_RAW_FILE | Path to save the raw metrics and data too | nil
BENCHER_REPORT | Path to save the report output too | STDOUT
BENCHER_FORMAT | Format of the report (csv
or json
) | csv
A simple bash wrapper could look like this:
#!/usr/bin/env bash
test_dir=${HOME}/Desktop/bencher_tests
export BENCHER_RAW_FILE=${test_dir}/bencher_raw.json
export BENCHER_REPORT=${test_dir}/bencher.csv
export BENCHER_FORMAT=csv
crystal build --release -Dbenchmark ./src/main.cr -o ./bin/main
./bin/main
You could then find the report output in ${HOME}/Desktop/bencher_tests
Contributing
- Fork it (https://github.com/spoved/bencher.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Holden Omans - creator and maintainer