Created
February 3, 2010 21:32
-
-
Save mtodd/294049 to your computer and use it in GitHub Desktop.
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' | |
N = 1_000_000 | |
data = {:x => 1, :y => 2, :z => 3} | |
key = :usage | |
token = "asdf1234ghij5678klmn90op" | |
data_dump = Marshal.dump(data) | |
payload_str = Marshal.dump([key, token, data]) | |
payload_dump = Marshal.dump([key, token, data_dump]) | |
Benchmark.bmbm(15) do |x| | |
x.report("dump str") do | |
Marshal.dump([key, token, data]) | |
end | |
x.report("dump dump") do | |
Marshal.dump([key, token, Marshal.dump(data)]) | |
end | |
x.report("load str") do | |
Marshal.load(payload_str) | |
end | |
x.report("load dump") do | |
Marshal.load(payload_dump) | |
end | |
end | |
lskey, lstoken, lsdata = Marshal.load(payload_str) | |
ldkey, ldtoken, lddata = Marshal.load(payload_dump) | |
puts "*"*80 | |
if lskey == key and ldkey == key | |
puts "keys OK" | |
else | |
puts "keys FAIL" | |
end | |
if lstoken == token and ldtoken == token | |
puts "token OK" | |
else | |
puts "token FAIL" | |
end | |
if lsdata == data and Marshal.load(lddata) == data | |
puts "data OK" | |
else | |
puts "data FAIL" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment