Skip to content
Benoit Daloze edited this page Jul 2, 2012 · 8 revisions

There are two kind of benchmarks:

  • counting iterations: for a fast single operation
  • time for a given n: for an operation depending on the size of the given input

Here are some ideas for the API:

Prefer.session do |b|
  b.iterations 'File.stat' do
    File.stat(Dir.tmpdir)
  end

  b.bench 'Array#sort' do |n|
    ary = Array.new(n) { rand(n) }

    b.measure do
      ary.sort
    end
  end
end

Clone this wiki locally