Topic: performance problem with long table

hello there all
i am pulling plots to make a graph but it is taking a long long time.
in the tail -f development.log, i see "showing fields from " for a long long time.
it seems to pull the query in less than a second. but takes a long time to process through the following code.
is there a reason this is taking so long that i can clean up?

raw_plots =
raw_times =
plots =
times =
records = FlowHit.find(:all,
     :conditions => ['flow_sensor_id = ? and date_time < ?',
      :order => 'date_time')
records.each_with_index do |hit, i|
     if i > 3 # start with 3rd hit in db     
     if hit.raw != records[i-1].raw # only calculate on change in value
           # if this raw is greater than the last, the chip has rolled
           if hit.raw < records[i-1].raw
           roll_overs += 1
           plot_point = ((hit.raw + (roll_overs * bit_multiplier)) * multiplier);
total_plots = raw_plots.size
raw_plots.each_with_index do |raw_plot, i|
# have to break off when plots gets to 4 less than total
   if i < (total_plots -4)
      start_value = raw_plot
      end_value = raw_plots[i+3]
      start_time = raw_times[i]
      end_time = raw_times[3]
      duration = (end_time.to_i - start_time.to_i) / 60
      value = (end_value - start_value) / duration

thanks for any tips or ideas.


Re: performance problem with long table

You need to figure out which part of the code is the bottleneck. One way to do this is place little markers throughout the code: 'mark 1'

You can then see in the log what marks are called before/after the problem spot.

Railscasts - Free Ruby on Rails Screencasts

Re: performance problem with long table

ok, did not know about being able to do this. thanks !