Created
May 4, 2021 22:46
-
-
Save SamSaffron/df1a982f065b85c1861905c5a3171448 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
numbers = (1..10000).to_a | |
numbers_as_string = "," + (1..10000).to_a.join(",") + "," | |
Benchmark.ips do |x| | |
x.report("binary search numbers") do |i| | |
while i > 0 | |
numbers.bsearch { |x| x == 77 } | |
i -= 1 | |
end | |
end | |
x.report("numbers") do |i| | |
while i > 0 | |
numbers.include?(5000) | |
i -= 1 | |
end | |
end | |
x.report("string") do |i| | |
while i > 0 | |
numbers_as_string.include?(",5000,") | |
i -= 1 | |
end | |
end | |
x.compare! | |
end |
Author
SamSaffron
commented
May 4, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment