Created
January 30, 2010 05:07
-
-
Save actsasflinn/290425 to your computer and use it in GitHub Desktop.
Message Pack vs similar utilities
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
=begin | |
Message Pack vs similar utilities | |
ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.0.0], MBARI 0x6770, Ruby Enterprise Edition 2010.02 | |
Packing | |
user system total real | |
pack: bert 18.320000 0.770000 19.090000 ( 19.101583) | |
pack: bson_ext 0.850000 0.030000 0.880000 ( 0.878398) | |
pack: json_ext 2.540000 0.040000 2.580000 ( 2.582495) | |
pack: marshal 0.820000 0.010000 0.830000 ( 0.827282) | |
pack: message pack 0.180000 0.000000 0.180000 ( 0.192843) | |
pack: ox 0.160000 0.000000 0.160000 ( 0.170643) | |
pack: yajl 1.100000 0.170000 1.270000 ( 1.278636) | |
Unpacking | |
user system total real | |
unpack: bert 1.170000 0.010000 1.180000 ( 1.191251) | |
unpack: bson_ext 6.180000 0.120000 6.300000 ( 6.300053) | |
unpack: json_ext 1.020000 0.130000 1.150000 ( 1.148061) | |
unpack: marshal 0.900000 0.010000 0.910000 ( 0.918656) | |
unpack: message pack 0.280000 0.080000 0.360000 ( 0.373574) | |
unpack: ox 1.320000 0.040000 1.360000 ( 1.383723) | |
unpack: yajl 1.220000 0.210000 1.430000 ( 1.502198) | |
Message Sizes | |
================================= | |
BERT Size : 165 | |
BSON Size : 88 | |
JSON Size : 90 | |
Marshal Size : 82 | |
Message Pack Size: 73 | |
Ox Size : 156 | |
YAJL Size : 90 | |
=end | |
=begin | |
Message Pack vs similar utilities | |
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin11.2.0] | |
Packing | |
user system total real | |
pack: bert 19.210000 0.260000 19.470000 ( 19.780369) | |
pack: bson_ext 0.890000 0.010000 0.900000 ( 0.905407) | |
pack: json_ext 2.510000 0.030000 2.540000 ( 2.581175) | |
pack: marshal 0.760000 0.000000 0.760000 ( 0.765014) | |
pack: message pack 0.200000 0.010000 0.210000 ( 0.206331) | |
pack: ox 0.160000 0.000000 0.160000 ( 0.166587) | |
pack: yajl 1.110000 0.090000 1.200000 ( 1.201324) | |
Unpacking | |
user system total real | |
unpack: bert 1.200000 0.000000 1.200000 ( 1.207462) | |
unpack: bson_ext 6.000000 0.070000 6.070000 ( 6.070004) | |
unpack: json_ext 1.030000 0.040000 1.070000 ( 1.077090) | |
unpack: marshal 0.850000 0.000000 0.850000 ( 0.849543) | |
unpack: message pack 0.440000 0.100000 0.540000 ( 0.549752) | |
unpack: ox 0.630000 0.030000 0.660000 ( 0.715224) | |
unpack: yajl 1.300000 0.150000 1.450000 ( 1.468837) | |
Message Sizes | |
================================= | |
BERT Size : 165 | |
BSON Size : 88 | |
JSON Size : 90 | |
Marshal Size : 82 | |
Message Pack Size: 73 | |
Ox Size : 156 | |
YAJL Size : 90 | |
=end | |
=begin | |
Message Pack vs similar utilities | |
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0] | |
Packing | |
user system total real | |
pack: bert 29.760000 0.090000 29.850000 ( 29.932918) | |
pack: bson_ext 0.830000 0.010000 0.840000 ( 0.835913) | |
pack: json_ext 5.040000 0.030000 5.070000 ( 5.080224) | |
pack: marshal 0.940000 0.010000 0.950000 ( 0.943183) | |
pack: message pack 0.200000 0.000000 0.200000 ( 0.200396) | |
pack: ox 0.150000 0.000000 0.150000 ( 0.155887) | |
pack: yajl 0.910000 0.020000 0.930000 ( 0.932505) | |
Unpacking | |
user system total real | |
unpack: bert 0.970000 0.000000 0.970000 ( 0.984114) | |
unpack: bson_ext 1.930000 0.010000 1.940000 ( 1.936163) | |
unpack: json_ext 1.350000 0.000000 1.350000 ( 1.357848) | |
unpack: marshal 1.180000 0.000000 1.180000 ( 1.179626) | |
unpack: message pack 0.220000 0.060000 0.280000 ( 0.505087) | |
unpack: ox 0.490000 0.030000 0.520000 ( 0.514418) | |
unpack: yajl 0.990000 0.070000 1.060000 ( 1.063659) | |
Message Sizes | |
================================= | |
BERT Size : 165 | |
BSON Size : 88 | |
JSON Size : 90 | |
Marshal Size : 109 | |
Message Pack Size: 73 | |
Ox Size : 156 | |
YAJL Size : 90 | |
=end | |
=begin | |
** Ox not supported on Rubinus | |
Message Pack vs similar utilities | |
rubinius 2.0.0dev (1.8.7 0988e049 yyyy-mm-dd JI) [x86_64-apple-darwin11.2.0] | |
Packing | |
user system total real | |
pack: bert 14.279247 0.069898 14.349145 ( 13.767398) | |
pack: bson_ext 4.591783 0.036679 4.628462 ( 4.633223) | |
pack: json_ext 8.323556 0.054664 8.378220 ( 8.290378) | |
pack: marshal 21.749998 0.081250 21.831248 ( 21.384594) | |
pack: message pack 2.423002 0.016428 2.439430 ( 2.468664) | |
pack: yajl 4.288820 0.035307 4.324127 ( 4.262729) | |
Unpacking | |
user system total real | |
unpack: bert 6.624596 0.061075 6.685671 ( 6.705766) | |
unpack: bson_ext 5.641032 0.031776 5.672808 ( 5.683171) | |
unpack: json_ext 6.369278 0.061602 6.430880 ( 6.435611) | |
unpack: marshal 4.886334 0.019704 4.906038 ( 4.638839) | |
unpack: message pack 3.476686 0.035722 3.512408 ( 3.507734) | |
unpack: yajl 6.502833 0.055244 6.558077 ( 6.548645) | |
Message Sizes | |
================================= | |
BERT Size : 165 | |
BSON Size : 88 | |
JSON Size : 90 | |
Marshal Size : 82 | |
Message Pack Size: 73 | |
YAJL Size : 90 | |
=end | |
TEST_SIZE = 100000 | |
HEADING_OFFSET = 30 | |
CAPTION_OFFSET = " " * (RUBY_VERSION =~ /^1\.8/ ? HEADING_OFFSET : 0) | |
puts "Message Pack vs similar utilities" | |
puts RUBY_DESCRIPTION | |
require 'rubygems' | |
require 'benchmark' | |
require 'msgpack' | |
require 'json' | |
require 'yajl' | |
require 'mongo' | |
require 'bert' | |
require 'ox' | |
duck = { 'sound' => 'quack', 'name' => 'Daffy', 'feet' => 2, 'wings' => true } | |
dude = { 'sound' => "I'm the dude!", 'name' => 'Lebowski', 'missing a rug' => true, 'missing money' => 1_000_000.00 } | |
puts "\nPacking\n" | |
packs = { | |
"bert" => proc{ BERT.encode(duck) }, | |
"bson_ext" => proc{ BSON.serialize(duck) }, | |
"json_ext" => proc{ JSON.dump(duck) }, | |
"marshal" => proc{ Marshal.dump(duck) }, | |
"message pack" => proc{ MessagePack.pack(duck) }, | |
"ox" => proc{ Ox.dump(duck) }, | |
"yajl" => proc{ Yajl::Encoder.encode(duck) }, | |
} | |
Benchmark.benchmark(CAPTION_OFFSET + Benchmark::Tms::CAPTION, HEADING_OFFSET) do |b| | |
packs.keys.sort.each do |name| | |
test = packs[name] | |
b.report("pack: " + name) do | |
TEST_SIZE.times(&test) | |
end | |
GC.start | |
end | |
end | |
puts "\nUnpacking\n" | |
Benchmark.benchmark(CAPTION_OFFSET + Benchmark::Tms::CAPTION, HEADING_OFFSET) do |b| | |
br = BERT.encode(dude) | |
bs = BSON.serialize(dude) | |
js = JSON.dump(dude) | |
ms = Marshal.dump(dude) | |
mp = MessagePack.pack(dude) | |
ox = Ox.dump(dude) | |
yj = Yajl::Encoder.encode(dude) | |
unpacks = { | |
"bert" => proc{ BERT.decode(br) }, | |
"bson_ext" => proc{ BSON.deserialize(bs) }, | |
"json_ext" => proc{ JSON.parse(js) }, | |
"marshal" => proc{ Marshal.load(ms) }, | |
"message pack" => proc{ MessagePack.unpack(mp) }, | |
"ox" => proc{ Ox.parse_obj(ox) }, | |
"yajl" => proc{ Yajl::Parser.parse(yj) }, | |
} | |
unpacks.keys.sort.each do |name| | |
test = unpacks[name] | |
b.report("unpack: " + name) do | |
TEST_SIZE.times(&test) | |
end | |
GC.start | |
end | |
puts "\nMessage Sizes" | |
puts "=================================" | |
puts "BERT Size : #{br.size}" | |
puts "BSON Size : #{bs.size}" | |
puts "JSON Size : #{js.size}" | |
puts "Marshal Size : #{ms.size}" | |
puts "Message Pack Size: #{mp.size}" | |
puts "Ox Size : #{ox.size}" | |
puts "YAJL Size : #{yj.size}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment