Skip to content

Instantly share code, notes, and snippets.

@banesto
Created November 11, 2015 15:30
Show Gist options
  • Save banesto/c6d781671eb07f4cdde4 to your computer and use it in GitHub Desktop.
Save banesto/c6d781671eb07f4cdde4 to your computer and use it in GitHub Desktop.
any? vs include?
require 'benchmark'
iterations = 100_000
Benchmark.bm do |bm|
bm.report do
iterations.times do
"a,b,c,d".split(',').any? { |letter| letter == 'd' }
end
end
bm.report do
iterations.times do
"a,b,c,d".split(',').include?('d')
end
end
bm.report do
iterations.times do
'd'.in?("a,b,c,d".split(','))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment