简体   繁体   中英

What is the best way to test performance of the query Rails

I have tested the Rails query with Ruby Benchmark:

puts Benchmark.measure { 
  @product_providers = SiteController.fetch_providers(@product_types.keys)
}

This is basically the query, to join product_provider table with product_type , but the logic of query lies outside of the scope of the question.

protected

def self.fetch_providers product_types
    fetched_providers = {}
    if product_types && product_types.kind_of?(Array)
        product_types.each do |product_type|
            fetched_providers.merge!( { product_type.underscore => product_type.constantize.joins(:provider) } )
        end
    end
    fetched_providers
end

My question is:

Why testing the query inside Ruby Bencmark, the result that I get is:

0.000000   0.000000   0.000000 (  0.000796)

However when I run query inside of the rails console I get results after 4-6 seconds :)

您可以使用mini profiler来测试性能http://miniprofiler.com/以及与此主题有关的railscasts http://railscasts.com/episodes/368-miniprofiler

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM