Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cibernox/bencher
Simplest benchmarking library for ruby
https://github.com/cibernox/bencher
Last synced: 17 days ago
JSON representation
Simplest benchmarking library for ruby
- Host: GitHub
- URL: https://github.com/cibernox/bencher
- Owner: cibernox
- License: mit
- Created: 2014-05-01T16:59:36.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-02-20T09:52:49.000Z (almost 7 years ago)
- Last Synced: 2024-10-29T20:12:39.719Z (2 months ago)
- Language: Ruby
- Size: 5.86 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Bencher
Simple library to run the simples benchmarks possible.
Just measure times and objects allocation.
## Installation
Add this line to your application's Gemfile:
gem 'bencher'
And then execute:
$ bundle
Or install it yourself as:
$ gem install bencher
## Usage
You can create benchmarks just writting classes that inherit from
`Bencher::Benchmark`.Those classes **must** define a `benchmark` method where you place the code to
be measured.```ruby
class MyBenchmark < Bencher::Benchmark
def benchmark(reporter)
repetitions = 1_000_000reporter.report "#method_a" do
repetitions.times do |number|
method_a(number)
end
endreporter.report "#method_b" do
repetitions.times do |number|
method_b(number)
end
end
end
end
```You can run the benchmarks from inside the console
```
[1] pry(main)> require_relative "benchmarks/my_benchmark" # => true
[2] pry(main)> LoadSquadBenchmark.new.run
=> [#,
#,
{:TOTAL=>8858772, :FREE=>-179860, :T_OBJECT=>393666, :T_CLASS=>3577,
:T_MODULE=>7, :T_FLOAT=>0, :T_STRING=>4047708, ... }
]
```Or using the command line utility:
```
$ bundle exec bencher benchmarks/
user system total real
5.940000 0.550000 6.490000 ( 8.107446)
2.750000 0.260000 3.010000 ( 3.564494)
1.940000 0.290000 2.230000 ( 3.160562)
{:TOTAL=>8982685, :T_OBJECT=>393666, :T_CLASS=>3577, :T_MODULE=>7, :T_FLOAT=>0, :T_STRING=>4099013, ...}
```## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request