require 'benchmark'
require 'ostruct'
Rails.logger.level = 1
n = 100000

Benchmark.bm do |x|
  x.report("10 variables") do
    a, b, c, d, e, f, g, e, h, m = [1, 2, 3, 4, 5, '6', '7', '8', '9', '10']
    Rails.cache.write('a', a)
    Rails.cache.write('b', b)
    Rails.cache.write('c', c)
    Rails.cache.write('d', d)
    Rails.cache.write('e', e)
    Rails.cache.write('f', f)
    Rails.cache.write('g', g)
    Rails.cache.write('e', e)
    Rails.cache.write('h', h)
    Rails.cache.write('m', m)

    n.times do
      a = Rails.cache.read('a')
      b = Rails.cache.read('b')
      c = Rails.cache.read('c')
      d = Rails.cache.read('d')
      e = Rails.cache.read('e')
      f = Rails.cache.read('f')
      g = Rails.cache.read('g')
      e = Rails.cache.read('e')
      h = Rails.cache.read('h')
      m = Rails.cache.read('m')
    end
  end

  x.report("hash with 10 variables") do
    hash = {
      'a' => 1,
      'b' => 2,
      'c' => 3,
      'd' => 4,
      'e' => 5,
      'f' => '6',
      'g' => '7',
      'e' => '8',
      'h' => '9',
      'm' => '10'
    }
    Rails.cache.write('hash', hash)

    n.times do
      hash = Rails.cache.read('hash')
    end 

  end

  x.report("array with 10 variables") do
    array = [
      ['a', 1],
      ['b', 2],
      ['c', 3],
      ['d', 4],
      ['e', 5],
      ['f', '6'],
      ['g', '7'],
      ['e', '8'],
      ['h', '9'],
      ['m', '10'],
    ]
    Rails.cache.write('array', array)

    n.times do
      array = Rails.cache.read('array')
    end 

  end

end

user system total real
10 variables 42.670000 8.200000 50.870000 ( 52.095375)
hash with 10 variables 6.390000 0.810000 7.200000 ( 7.303731)
array with 10 variables 6.350000 0.820000 7.170000 ( 7.279306)