Created
July 27, 2011 00:31
-
-
Save jerhinesmith/1108427 to your computer and use it in GitHub Desktop.
yaml/json serialization
This file contains hidden or 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 'json' | |
require 'yaml' | |
iterations = 10_000 | |
message = {:to => 'Justin', :from => 'Andres', :subject => 'Foosball Game', :body => "Hey, sorry that I left without at least asking anyone if they wanted to play a quick game of foosball. That was really dumb. Next time I won't be dumb about that."} | |
message_yaml = YAML::dump(message) | |
message_json = message.to_json | |
Benchmark.bm(10) do |x| | |
x.report("YAML::dump") { (1..iterations).each{|i| YAML::dump(message)} } | |
x.report("to_json") { (1..iterations).each{|i| message.to_json} } | |
x.report("YAML::load") { (1..iterations).each{|i| YAML::load(message_yaml)} } | |
x.report("JSON.parse") { (1..iterations).each{|i| JSON.parse(message_json)} } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment