Skip to content

Instantly share code, notes, and snippets.

@akahn
Forked from bkeepers/output
Created July 9, 2011 00:33
Show Gist options
  • Select an option

  • Save akahn/1073136 to your computer and use it in GitHub Desktop.

Select an option

Save akahn/1073136 to your computer and use it in GitHub Desktop.
$ ruby serialization.rb
Sizes:
marshal: 55
msgpack: 35
json: 46
Rehearsal -----------------------------------------------------
marshal 1.590000 0.050000 1.640000 ( 1.647142)
json 1.890000 0.200000 2.090000 ( 2.091030)
marshal with yajl 1.590000 0.030000 1.620000 ( 1.624589)
json with yajl 1.860000 0.060000 1.920000 ( 1.926875)
msgpack 0.600000 0.050000 0.650000 ( 0.646675)
-------------------------------------------- total: 7.920000sec
user system total real
marshal 1.590000 0.050000 1.640000 ( 1.645221)
json 1.870000 0.350000 2.220000 ( 2.218516)
marshal with yajl 1.570000 0.040000 1.610000 ( 1.605292)
json with yajl 1.860000 0.310000 2.170000 ( 2.171474)
msgpack 0.580000 0.040000 0.620000 ( 0.620065)
require 'rubygems'
require 'benchmark'
require 'msgpack'
require 'json'
require 'yajl'
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('json') do
100_000.times do
JSON.parse(object.to_json)
end
end
require 'yajl/json_gem'
x.report('marshal with yajl') do
100_000.times do
Marshal.load(Marshal.dump(object))
end
end
x.report('json with yajl') do
100_000.times do
JSON.parse(object.to_json)
end
end
x.report('msgpack') do
100_000.times do
MessagePack.unpack(object.to_msgpack)
end
end
end
@akahn
Copy link
Copy Markdown
Author

akahn commented Jul 9, 2011

This benchmark sucks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment