-
-
Save miguelsan/783696 to your computer and use it in GitHub Desktop.
This file contains hidden or 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' | |
class Dummy | |
@VALID_OPTIONS = :first, :last, :all | |
class << self | |
def when_find(*args) | |
case args.first | |
when *@VALID_OPTIONS | |
send(args.first) | |
else | |
find_with_ids(*args) | |
end | |
end | |
def include_find(*args) | |
if @VALID_OPTIONS.include? args.first | |
send(args.first) | |
else | |
find_with_ids(*args) | |
end | |
end | |
def first;end | |
def last;end | |
def all;end | |
def find_with_ids(*args);end | |
end | |
end | |
Benchmark.bmbm do |bm| | |
bm.report("first with when:") { Dummy.when_find :first } | |
bm.report("first with include?:") { Dummy.include_find :first } | |
bm.report("last with when:") { Dummy.when_find :last } | |
bm.report("last with include?:") { Dummy.include_find :last } | |
bm.report("all with when:") { Dummy.when_find :all } | |
bm.report("all with include?:") { Dummy.include_find :all } | |
bm.report("ids with when:") { Dummy.when_find [1,2,3] } | |
bm.report("ids with include?:") { Dummy.include_find [1,2,3] } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment