Last active
December 17, 2016 15:34
-
-
Save sonalkr132/516f92c0857811cfb9d8b33096efd888 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/ips' | |
Benchmark.ips do |x| | |
x.report("reverse_dependencies_name") do | |
# inspect or else it will benchmark just the creation of sql query | |
# and not the execution | |
Version.reverse_dependencies('rails').inspect | |
end | |
x.report("reverse_dependencies_id") do | |
rails = Rubygem.find_by(name: 'rails') | |
Version.reverse_dependencies_by_id(rails.id).inspect | |
end | |
x.compare! | |
end |
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
#... | |
def self.reverse_dependencies(name) | |
joins(dependencies: :rubygem) | |
.indexed | |
.where(rubygems: { name: name }) | |
end | |
def self.reverse_dependencies_by_id(id) | |
joins(:dependencies) | |
.indexed | |
.where(dependencies: { rubygem_id: id } ) | |
end | |
#... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment