Last active
December 16, 2015 22:09
-
-
Save EricR/5505404 to your computer and use it in GitHub Desktop.
psych yaml vs. json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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