README.md in benches-0.2.0 vs README.md in benches-0.3.0

- old
+ new

@@ -1,36 +1,53 @@ # Benches -Benches defines a simple benchmarking DSL that allows you to create benchmark routines for your Ruby code. +Benches defines a simple rspec matcher that allows you to create benchmarking specs for your Ruby code. -## Defining a Routine +## Usage -Create a folder called regimens. For each class that you want to benchmark, -create a file like integer_regimen.rb +To include the matchers in your specs, set up your `spec_helper.rb` like so: +```ruby + require 'benches' + # other requirements -integer_regimen.rb + RSpec.configure do |config| + config.include Benches::Matchers + #other configuration code + end +``` + +The run_in_less_than matcher expects a block and checks if the block runs in less than a certain amount of time. + ```ruby -subject 5 do - benches '500 reps of to_s in less than 5 seconds' - benches '400 reps of + in less than 2 seconds', 3 - benches '300 reps of * in less than 3 seconds', 400 -end + describe Integer + describe 'to_s' do + it 'meets the performance metrics when running 1 time' do + expect{5.to_s}.to run_in_less_than(1.second) + end + end + end +``` -subject 20 do - benches '500 reps of to_s in less than 5 seconds' - benches '400 reps of + in less than 2 seconds', 3 - benches '300 reps of * in less than 3 seconds', 400 +You can also specify that a block should run a certain number of times in less than a certain duration. + +```ruby +describe Integer do + describe 'to_s' do + it 'meets the performance metrics' do + expect{5.to_s}.to run(500).times_in_less_than(5.seconds) + end + end end ``` -If the benchmarks runs within the allotted time, it will -be printed green, otherwise it will be printed red. +The duration specified should be an ActiveSupport::Duration object, like `5.seconds` or `1.hour`. -The command `benchpress` runs all of the regimen files +If the benchmark runs within the allotted time, the test will pass. +Otherwise it will fail. ## Testing -Simply run `rspec` to run the test suite. +Simply run `rspec` to run the sample spec. ## Credits All code (c) Evan Hemsley 2014