summaryrefslogtreecommitdiff
path: root/benchmarks/keep_original_mash_keys.rb
blob: 3f20eb979380b00e6e493b3fb295c71a601b759e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require_relative '../lib/hashie'
require 'benchmark/ips'

class KeepingMash < Hashie::Mash
  include Hashie::Extensions::Mash::KeepOriginalKeys
end

original = { test: 'value' }
mash = Hashie::Mash.new(original)
keeping_mash = KeepingMash.new(original)

Benchmark.ips do |x|
  x.report('keep symbol') { keeping_mash.test }
  x.report('normal symbol') { mash.test }

  x.compare!
end

original = { 'test' => 'value' }
mash = Hashie::Mash.new(original)
keeping_mash = KeepingMash.new(original)

Benchmark.ips do |x|
  x.report('keep string') { keeping_mash.test }
  x.report('normal string') { mash.test }

  x.compare!
end