Skip to content

Instantly share code, notes, and snippets.

@sorentwo
Created June 8, 2016 23:56
Show Gist options
  • Save sorentwo/80113419505cf2f028db0eb6729fa031 to your computer and use it in GitHub Desktop.
Save sorentwo/80113419505cf2f028db0eb6729fa031 to your computer and use it in GitHub Desktop.
Benchmarking and tuning the performance of Cache#read_multi with refreshing
require 'benchmark/ips'
require 'readthis'
cache = Readthis::Cache.new(namespace: 'rd', expires_in: 60)
range = ('a'..'z').to_a
range.each { |key| cache.write(key, key) }
Benchmark.ips do |x|
x.report 'read_multi:standard' do
cache.read_multi(*range.sample(15))
end
x.report 'read_multi:refresh' do
cache.read_multi(*range.sample(15), refresh: true)
end
x.report 'read_multi:lua' do
cache.lua_read_multi(*range.sample(15), refresh: true)
end
x.compare!
end
Press ENTER or type command to continue
Calculating -------------------------------------
read_multi:standard 452.000 i/100ms
read_multi:refresh 139.000 i/100ms
read_multi:lua 456.000 i/100ms
-------------------------------------------------
read_multi:standard 4.579k (± 3.4%) i/s - 23.052k
read_multi:refresh 1.410k (± 1.8%) i/s - 7.089k
read_multi:lua 4.571k (± 4.6%) i/s - 22.800k
Comparison:
read_multi:standard: 4579.2 i/s
read_multi:lua: 4571.3 i/s - 1.00x slower
read_multi:refresh: 1409.7 i/s - 3.25x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment