Skip to content

Instantly share code, notes, and snippets.

@EricR
Last active December 16, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricR/5505404 to your computer and use it in GitHub Desktop.
Save EricR/5505404 to your computer and use it in GitHub Desktop.
psych yaml vs. json
require 'benchmark'
require 'psych'
require 'json'
some_data = {:user => {:name => ["Joe", "Smith"]}, :product => {:id => 2, :name => "Whatever"}, :some_long_string => "s" * 2000, :some_long_number => 1000000000 * 100000000000}
some_yaml = some_data.to_yaml
some_json = some_data.to_json
Benchmark.bm do |b|
b.report("yaml parse") { Psych.load(some_yaml) }
b.report("json parse") { JSON.parse(some_json) }
end
# user system total real
# yaml parse 0.000000 0.000000 0.000000 ( 0.001455)
# json parse 0.000000 0.000000 0.000000 ( 0.000074)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment