Skip to content

Instantly share code, notes, and snippets.

@alexeevit
Last active December 5, 2019 07:49
Show Gist options
  • Save alexeevit/c0f7030076aeab0e5b136826c9924f51 to your computer and use it in GitHub Desktop.
Save alexeevit/c0f7030076aeab0e5b136826c9924f51 to your computer and use it in GitHub Desktop.
How to benchmark a method in ruby
require 'benchmark'
data = (0..50_000_000)
Benchmark.bm do |x|
x.report(:find) { data.find { |number| number > 40_000_000 } }
x.report(:bsearch) { data.bsearch { |number| number > 40_000_000 } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment