Skip to content

Instantly share code, notes, and snippets.

@gkop
Last active December 11, 2015 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkop/4590606 to your computer and use it in GitHub Desktop.
Save gkop/4590606 to your computer and use it in GitHub Desktop.
require 'benchmark'
array = (0..10000000).to_a
benchmark = Benchmark.bm(10) do |x|
x.report("Ruby 2.0: ") do
100000.times { array.bsearch { |e| 7777777 <=> e } }
end
require 'bsearch'
x.report("bsearch gem:") do
100000.times { array.bsearch { |e| 7777777 <=> e } }
end
end
# user system total real
# Ruby 2.0: 0.180000 0.000000 0.180000 ( 0.185011)
# bsearch gem: 0.750000 0.000000 0.750000 ( 0.761949)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment