Created
February 25, 2015 07:34
-
-
Save almostwhitehat/1722cd54c09d034274b5 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' | |
ARRAY = [*1..100] | |
def slow | |
ARRAY.select { |x| x.eql?(50) }.last | |
end | |
def fast | |
ARRAY.reverse.detect { |x| x.eql?(50) } | |
end | |
Benchmark.ips do |x| | |
x.report('slow') { slow } | |
x.report('fast') { fast } | |
x.compare! | |
end |
Author
almostwhitehat
commented
Feb 25, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment