Created
September 22, 2009 05:55
-
-
Save visfleet/190849 to your computer and use it in GitHub Desktop.
Revisions
-
visfleet created this gist
Sep 22, 2009 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ require 'benchmark' require 'yaml' def encode(msg, format) case format when :yaml str = msg.to_yaml when :binary str = Marshal.dump(msg) end str.gsub!("\n", '--\\n') str end def decode(str, format) case format when :yaml YAML.load(str) when :binary Marshal.load(str) end str.gsub!('--\\n', "\n") end SAMPLES = 1000 obj = {:test => "me"} Benchmark.bm do |r| r.report("Marshal") do SAMPLES.times do decode(encode(obj, :binary), :binary) end end r.report("YAML") do SAMPLES.times do decode(encode(obj, :yaml), :yaml) end end end # Results # user system total real # Marshal 0.020000 0.000000 0.020000 (0.025426) # YAML 0.210000 0.010000 0.220000 (0.218788)