Skip to content

Instantly share code, notes, and snippets.

@bkeepers
Created July 8, 2011 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bkeepers/1072879 to your computer and use it in GitHub Desktop.
Save bkeepers/1072879 to your computer and use it in GitHub Desktop.
$ ruby serialization.rb
Sizes:
marshal: 44
msgpack: 35
json: 46
Rehearsal -------------------------------------------
marshal 0.840000 0.030000 0.870000 ( 0.878109)
msgpack 0.420000 0.060000 0.480000 ( 0.467086)
json 1.310000 0.130000 1.440000 ( 1.444504)
---------------------------------- total: 2.790000sec
user system total real
marshal 0.850000 0.030000 0.880000 ( 0.872736)
msgpack 0.290000 0.030000 0.320000 ( 0.319910)
json 1.230000 0.110000 1.340000 ( 1.338845)
require 'rubygems'
require 'benchmark'
require 'msgpack'
require 'json'
Benchmark.bmbm do |x|
object = {:id => 'asdf;lkjr2l;kjdsokj23', :hit => {:a => 'b'}}
puts "Sizes:",
"marshal: #{Marshal.dump(object).length}",
"msgpack: #{object.to_msgpack.length}",
"json: #{object.to_json.length}"
x.report('marshal') do
100_000.times do
Marshal.load(Marshal.dump(object))
end
end
x.report('msgpack') do
100_000.times do
MessagePack.unpack(object.to_msgpack)
end
end
x.report('json') do
100_000.times do
JSON.parse(object.to_json)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment