Skip to content

Instantly share code, notes, and snippets.

@andyjeffries
Created March 9, 2012 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyjeffries/2006182 to your computer and use it in GitHub Desktop.
Save andyjeffries/2006182 to your computer and use it in GitHub Desktop.
messagepack vs yajl
11:34 ~ $ irb
1.9.2p290 :001 > require 'rubygems'
=> false
1.9.2p290 :002 > require 'json'
=> true
1.9.2p290 :003 > require 'msgpack'
=> true
1.9.2p290 :004 > f = File.read('test.json'); nil # f is our calendar data
=> nil
1.9.2p290 :005 > h = JSON.parse(f); nil
=> nil
1.9.2p290 :007 > m = MessagePack.pack(h); nil
=> nil
1.9.2p290 :009 > require 'yajl'
=> true
# Time in millseconds to decode each
1.9.2p290 :010 > a = Time.now; h = Yajl::Parser.new.parse(f); nil; (Time.now-a)*1000
=> 144.823
1.9.2p290 :011 > a = Time.now; h = MessagePack.unpack(m); nil; (Time.now-a)*1000
=> 53.449000000000005
# Smaller uncompressed
1.9.2p290 :012 > m.size
=> 2351616
1.9.2p290 :013 > f.size
=> 4542940
# Smaller compressed
1.9.2p290 :016 > ActiveSupport::Gzip.compress(m).size
=> 135666
1.9.2p290 :017 > ActiveSupport::Gzip.compress(f).size
=> 165177
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment