Created
November 23, 2011 16:45
-
-
Save tastycode/1389171 to your computer and use it in GitHub Desktop.
Rails Cache Strategy Benchmarks
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
require 'benchmark' | |
task :benchmark => :environment do | |
stores = { | |
:file_store=>[Rails.root+"/tmp/cache"], | |
:mem_cache_store=>["localhost"], | |
:dalli_store=>["localhost"], | |
:redis_store=> [], | |
:mongo_store=> [], | |
} | |
actions = { | |
:hit => lambda { | |
Rails.cache.fetch("test") | |
}, | |
:miss => lambda { | |
Rails.cache.read("test"+rand().to_s[0..10]) | |
} | |
} | |
stores.each do |store,args| | |
ActionController::Base.cache_store = store, *args | |
puts "Cache Store: #{store}" | |
marks = Benchmark.bm(15) do |x| | |
actions.each do |label, proc| | |
puts "Action: #{label}" | |
Rails.cache.delete("test") | |
Rails.cache.fetch("test") { [Time.now, 1.year.ago] } | |
x.report("times:") do | |
20000.times do | |
proc.call | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Slight changes for Rails 6: https://gist.github.com/lzap/c0db20b6996d2ec04dbfd1dae1d10cb5
And .... thanks! :-)