Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$ 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