开发者

timing code in ruby/rails

开发者 https://www.devze.com 2023-02-06 22:41 出处:网络
I have a rake task/batch job that is taking too long and im trying to track down in production where the time is being spent. For now I have started adding:

I have a rake task/batch job that is taking too long and im trying to track down in production where the time is being spent. For now I have started adding:

   start_time = Time.now

   # logic

   end_time = Time.now
   elapsed_time = end_time - start_time
   puts "Elapsed time is #{elapsed_time} for this logic"

Is this the b开发者_C百科est way to do this? I dont want to install any external tools in production. I need finer grained timings that method levels, because I need to know what data was being used for each method/section etc.


I think you'll get the most bang for your buck using a profiler (like ruby-prof). This will show you exactly where your time is being spent.


There's the Benchmark module from the standard library that you could use. It shows th same kind of output as the time command. I would link you but I am on my phone, sorry.

0

精彩评论

暂无评论...
验证码 换一张
取 消