Skip to content

Instantly share code, notes, and snippets.

@tastycode
Created November 23, 2011 16:45
Show Gist options
  • Save tastycode/1389171 to your computer and use it in GitHub Desktop.
Save tastycode/1389171 to your computer and use it in GitHub Desktop.
Rails Cache Strategy Benchmarks
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
@lzap
Copy link

lzap commented Apr 23, 2020

Slight changes for Rails 6: https://gist.github.com/lzap/c0db20b6996d2ec04dbfd1dae1d10cb5

And .... thanks! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment