File: permissive_respond_to.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 (44 lines) | stat: -rwxr-xr-x 963 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env ruby

$LOAD_PATH.unshift File.expand_path(File.join('..', 'lib'), __dir__)

require 'hashie'
require 'benchmark/ips'
require 'benchmark/memory'

permissive = Class.new(Hashie::Mash)

Benchmark.memory do |x|
  x.report('Default') {}
  x.report('Make permissive') do
    permissive.include Hashie::Extensions::Mash::PermissiveRespondTo
  end
end

class PermissiveMash < Hashie::Mash
  include Hashie::Extensions::Mash::PermissiveRespondTo
end

Benchmark.ips do |x|
  x.report('Mash.new') { Hashie::Mash.new(a: 1) }
  x.report('Permissive.new') { PermissiveMash.new(a: 1) }

  x.compare!
end

Benchmark.ips do |x|
  x.report('Mash#attr=') { Hashie::Mash.new.a = 1 }
  x.report('Permissive#attr=') { PermissiveMash.new.a = 1 }

  x.compare!
end

mash = Hashie::Mash.new(a: 1)
permissive = PermissiveMash.new(a: 1)

Benchmark.ips do |x|
  x.report('Mash#attr= x2') { mash.a = 1 }
  x.report('Permissive#attr= x2') { permissive.a = 1 }

  x.compare!
end