bme: benchmark everything

BME is a simple wrapper around ruby's Benchmark library which helps you write benchmark code that is clearer, simpler, and more meaningful.

A normal benchmark with the 'benchmark' library can quickly get untidy:

require 'benchmark'

iterations = 100,000

Benchmark.bm do |bm|
  bm.report 'some_method' do
    iterations.times { Library.some_method(args) }
  end
end

As you add more benchmarks, those iterations will start to get in the way of the important code. A benchmark with BME is cleaner -- the code being tested is more apparent:

require 'bme'

BME.benchmark do |bm|
  bm.report 'some_method' do
    Library.some_method(args)
  end
end

By default, BME iterates over each piece of code 100,000 times. Use the :iterations option to override the default behaviour for all benchmarks:

BME.benchmark(:iterations => 500) do |bm|
  # ...
end

Or on a per-benchmark basis:

BME.benchmark do |bm|
  bm.report 'some_method' do
    Library.some_method(args)
  end

  bm.report 'other_method', :iterations => 500 do
    Library.other_method(args)
  end
end

That's it!

Installation

$ gem install bme --source http://gemcutter.org

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright (c) 2009 James Wilding. See LICENSE for details.