diff options
Diffstat (limited to 'benchmarks/permissive_respond_to.rb')
-rwxr-xr-x | benchmarks/permissive_respond_to.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/benchmarks/permissive_respond_to.rb b/benchmarks/permissive_respond_to.rb new file mode 100755 index 0000000..e7e894e --- /dev/null +++ b/benchmarks/permissive_respond_to.rb @@ -0,0 +1,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 |