Sha256: 7092a4b9b6d0bf99a25ae42fa89e7ec5b4ac1465c7be2c20e128ded567148e07

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

#!/usr/bin/env ruby
# 
# Benchmark for Viscacha
# 
require 'rubygems'
require 'bundler/setup'
require 'pathname'
require 'benchmark/ips'

require 'viscacha/store'
require 'active_support/cache/dalli_store'
require 'active_support/cache/mem_cache_store'
require 'active_support/cache/memory_store'

# CACHE_PATH = Pathname('bench.lmc')
# CACHE_PATH.delete if CACHE_PATH.exist?

SIZE = 64.megabytes
DATA = SecureRandom.random_bytes(25.kilobytes)
# DATA = { foo:12.34, bar:56, qux:nil }
SLOTS = SIZE / Marshal.dump(DATA).bytesize


CACHES = {
  viscacha: Viscacha::Store.new(name:'bench', directory:'.', size: 64.megabytes),
  memcache: ActiveSupport::Cache::MemCacheStore.new(size: 64.megabytes),
  dalli:    ActiveSupport::Cache::DalliStore.new,
  dalli_r:  ActiveSupport::Cache::DalliStore.new('kitekat.local:11211'),
  memory:   ActiveSupport::Cache::MemoryStore.new(size: 64.megabytes)
}

Benchmark.ips do |x|
  CACHES.each_pair do |name,cache|
    x.report("#{name} 100% miss") { cache.fetch(rand(10_000_000).to_s, compress:false) { DATA } }
    x.report("#{name} 100%  hit") { cache.fetch('foo',                 compress:false) { DATA } }
    x.report("#{name}  50%  hit") { cache.fetch(rand(SLOTS * 2).to_s,  compress:false) { DATA } }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
viscacha-0.0.1 bin/bench