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.
精彩评论