Last active
August 29, 2015 13:59
-
-
Save srt32/10674145 to your computer and use it in GitHub Desktop.
benchmark_funds.rake_v0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Benchmark funds_raised methods' | |
ITERATIONS = 100_000 | |
task benchmark_sql: :environment do | |
GC.disable | |
campaign = Campaign.last | |
Benchmark.bm do |bm| | |
bm.report('sql') do | |
ITERATIONS.times do | |
campaign.funds_raised_sql | |
Campaign.connection.clear_query_cache | |
end | |
end | |
end | |
GC.enable | |
end | |
task benchmark_ruby: :environment do | |
GC.disable | |
campaign = Campaign.last | |
Benchmark.bm do |bm| | |
bm.report('ruby') do | |
ITERATIONS.times do | |
campaign.funds_raised_ruby | |
Campaign.connection.clear_query_cache | |
end | |
end | |
end | |
GC.enable | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@croaky, sorry for the delay. I didn't see your comment. The data that is behind the benchmark is as you mentioned (with 1000 loans per campaign, actually)
The methods get called 100_000 times (perhaps too many times) to throw out any local blips or hiccups in memory, GC, other processes. The difference in time turned out to be so massive that, in the end, I think a single run would have sufficed.