Jackie Chan
Jackie Chan

Reputation: 2662

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 :)

Upvotes: 1

Views: 1552

Answers (1)

wedens
wedens

Reputation: 1830

you can use mini profiler to test performance http://miniprofiler.com/ and railscasts on this topic http://railscasts.com/episodes/368-miniprofiler

Upvotes: 1

Related Questions