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 |
@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)
campaigns = FactoryGirl.create_list(:campaign, 100)
campaigns.each do |campaign|
FactoryGirl.create_list(:loan, 1000, campaign: campaign)
end
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.
There is an updated gist at https://gist.github.com/srt32/10687302.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't think you want to execute the
campaign.funds_raised_sql
andcampaign.funds_raised_ruby
methods 100,000 times. I think you want to create 100,000+ records in the database (with something logical like 20-100 loans per campaign) and run those two methods once each, benchmarking their one execution time.