Topic: Speed of loop through Time object
I recently just posted here to try to pinpoint where my application was hanging up at. After a few tests in the console I found that the culprit lies in incrementing the loop. This is the code I am using:
date = Time.now start_date = 3.months.ago interval = (date-start_date)/10 (start_date..date).step(interval) do |cur_time| # A single DB query here that takes 1.5ms end
The total running time ended up being 542570ms. I tried this in the console replacing the DB query with a puts "test" and found that the time between the puts was ages. If I increased the interval divider (e,g 10 to say 500) it had a quicker frequency but still ran in the same amount of total time. Is there a quicker way to step through this Time object?