Skip to content

Instantly share code, notes, and snippets.

@byroot
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byroot/18ee6ce0e50fd12f5f76 to your computer and use it in GitHub Desktop.
Save byroot/18ee6ce0e50fd12f5f76 to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
require 'active_support/cache'
require 'memcached'
require 'active_support/cache/memcached_store'
require 'active_support/cache/dalli_store'
$dalli = ActiveSupport::Cache::DalliStore.new('127.0.0.1:11211')
$memcached = ActiveSupport::Cache::MemcachedStore.new('127.0.0.1:11211')
KEY = 'somekey'
SMALL_VALUE = 'a' * 30
BIG_VALUE = 'a' * 100_000
$dalli.write(KEY, BIG_VALUE)
$memcached.write(KEY, BIG_VALUE)
Benchmark.ips do |x|
x.report('dalli:read') { $dalli.read(KEY) }
x.report('memcached:read') { $memcached.read(KEY) }
x.report('dalli:write') { $dalli.write(KEY, SMALL_VALUE) }
x.report('memcached:write') { $memcached.write(KEY, SMALL_VALUE) }
x.report('dalli:write-big') { $dalli.write(KEY, BIG_VALUE) }
x.report('memcached:write-big') { $memcached.write(KEY, BIG_VALUE) }
end
\Calculating -------------------------------------
dalli:read 581.000 i/100ms
memcached:read 583.000 i/100ms
dalli:write 1.126k i/100ms
memcached:write 1.187k i/100ms
dalli:write-big 367.000 i/100ms
memcached:write-big 486.000 i/100ms
-------------------------------------------------
dalli:read 6.232k (± 4.9%) i/s - 31.374k
memcached:read 6.120k (± 4.0%) i/s - 30.899k
dalli:write 11.337k (±14.0%) i/s - 55.174k
memcached:write 12.656k (± 8.8%) i/s - 62.911k
dalli:write-big 3.792k (± 2.3%) i/s - 19.084k
memcached:write-big 4.668k (± 9.2%) i/s - 23.328k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment