Files
openfoodnetwork/spec/support/performance_helper.rb
2015-11-13 14:03:07 +11:00

21 lines
443 B
Ruby

module OpenFoodNetwork
module PerformanceHelper
def multi_benchmark(num_samples)
results = (0..num_samples).map do |i|
ActiveRecord::Base.connection.query_cache.clear
Rails.cache.clear
result = Benchmark.measure { yield }
puts result
result.total
end.drop(1) # Do not return the first sample
puts (results.sum / results.count * 1000).round 0
results
end
end
end