mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
21 lines
443 B
Ruby
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
|