Sha256: 9aab14dd972a4bd1f387e85230ca9cb4452d1dc5b18286559fb9afd0e871b436

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "paquito"
require "active_support"
require "benchmark/ips"

CODEC = Paquito::CodecFactory.build
ORIGINAL = Paquito::SingleBytePrefixVersion.new(
  0,
  0 => Paquito.chain(
    Paquito::CacheEntryCoder,
    CODEC,
  ),
)
FLAT = Paquito::FlatCacheEntryCoder.new(
  Paquito::SingleBytePrefixVersionWithStringBypass.new(
    0,
    0 => CODEC,
  ),
)

entries = {
  small_string: "Hello World!",
  bytes_1mb: Random.bytes(1_000_000),
  int_array: 1000.times.to_a,
}

entries.each do |name, object|
  entry = ActiveSupport::Cache::Entry.new(object, expires_at: 15.minutes.from_now.to_f)
  original_payload = ORIGINAL.dump(entry).freeze
  flat_payload = FLAT.dump(entry).freeze

  puts " === Read #{name} ==="
  Benchmark.ips do |x|
    x.report("original") { ORIGINAL.load(original_payload) }
    x.report("flat") { FLAT.load(flat_payload) }
    x.compare!(order: :baseline)
  end

  puts " === Write #{name} ==="
  Benchmark.ips do |x|
    x.report("original") { ORIGINAL.dump(entry) }
    x.report("flat") { FLAT.dump(entry) }
    x.compare!(order: :baseline)
  end

  puts
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
paquito-0.11.2 benchmark/flat-entry-coder.rb
paquito-0.11.1 benchmark/flat-entry-coder.rb
paquito-0.11.0 benchmark/flat-entry-coder.rb
paquito-0.10.0 benchmark/flat-entry-coder.rb
paquito-0.9.2 benchmark/flat-entry-coder.rb