File: keep_original_mash_keys.rb

package info (click to toggle)
ruby-hashie 5.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 884 kB
  • sloc: ruby: 7,049; sh: 8; makefile: 6
file content (28 lines) | stat: -rw-r--r-- 622 bytes parent folder | download | duplicates (2)
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