Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveRecord SQL execution time

How can I get the SQL query execution time in rails? I can see the time in logs, e.g.:

 Posting Load (10.8ms)  SELECT "postings".* FROM "postings" ORDER BY "postings"."id" ASC LIMIT 1

But how can I get that value (10.08) programmatically to use it further in my code?

like image 651
Eugene Korpan Avatar asked Aug 14 '13 19:08

Eugene Korpan


1 Answers

try this out

time_consumed = Benchmark.measure { Post.limit(1) }
like image 191
Sachin Singh Avatar answered Sep 27 '22 00:09

Sachin Singh