Sha256: 40ed97684af1938034e4eba451448ab638dab27094d13a0f723f06a87bb88b9a

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require 'bundler'

Bundler.setup

require 'benchmark'
require 'perforated'
require 'active_support/core_ext/object'
require 'redis'
require 'redis-activesupport'

Structure = Struct.new(:id) do
  def to_json
    { id: id, answers: %w[a b c d e f g], tags: [] }.to_json
  end
end

module Strategy
  def self.expand_cache_key(object)
    "perf-#{object}"
  end
end

perforated = Perforated::Cache.new((0..20_000).map { |i| Structure.new(i) }, Strategy)

Benchmark.bm do |x|
  GC.disable
  puts "Total Objects: #{ObjectSpace.count_objects[:TOTAL]}"

  x.report('memory-1') { perforated.to_json }
  x.report('memory-2') { perforated.to_json }

  puts "Total Objects: #{ObjectSpace.count_objects[:TOTAL]}"

  Perforated.configure do |config|
    config.cache = ActiveSupport::Cache::RedisStore.new(host: 'localhost', db: 5)
  end

  Perforated.cache.clear

  GC.enable
  GC.start
  GC.disable

  x.report('redis-1') { perforated.to_json }
  x.report('redis-2') { perforated.to_json }

  puts "Total Objects: #{ObjectSpace.count_objects[:TOTAL]}"
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
perforated-0.10.0 bench/giant.rb
perforated-0.9.1 bench/giant.rb
perforated-0.9.0 bench/giant.rb