Skip to content

Instantly share code, notes, and snippets.

@timgentry
Created March 10, 2017 09:36
Show Gist options
  • Save timgentry/ce9a6d0936825fa1ca3751cba92f0dc9 to your computer and use it in GitHub Desktop.
Save timgentry/ce9a6d0936825fa1ca3751cba92f0dc9 to your computer and use it in GitHub Desktop.
Benchmarking test of Marshal vs YAML serialise/deserialise object cloning
require 'benchmark'
require 'yaml'
n = 10_000
original = YAML.load <<-YML
- column: surname
rawtext_name: surname
mappings:
- field: surname
clean: :name
- column: forename
rawtext_name: forenames
mappings:
- field: forenames
clean: :name
- column: sex
rawtext_name: sex
mappings:
- field: sex
clean: :sex
- column: nhs_no
rawtext_name: nhsnumber
mappings:
- field: nhsnumber
clean: :nhsnumber
YML
Benchmark.bm do |x|
x.report("Marshal:") do
n.times { Marshal.load(Marshal.dump(original)) }
end
x.report(" YAML:") do
n.times { YAML.load(YAML.dump(original)) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment