Created
February 25, 2013 15:00
-
-
Save thejspr/5030366 to your computer and use it in GitHub Desktop.
JSON vs. Msgpack benchmark
This file contains hidden or 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
#!/usr/bin/env ruby | |
# JRuby | |
# gem install msgpack-jruby | |
# MRI | |
# gem install msgpack | |
require 'benchmark' | |
COUNT = ARGV[0].to_i || 10 | |
hash = { | |
wat: 'is this ' * 100, | |
nested: [{ element: 'x'*rand(10), wat: { is: 'this' } }]*100 | |
} | |
Benchmark.bm do |x| | |
x.report('msgpack') do | |
require 'msgpack' | |
COUNT.times do | |
pack = MessagePack.pack(hash) | |
MessagePack.unpack(pack) | |
end | |
end | |
x.report('json ') do | |
require 'json' | |
COUNT.times do | |
json = JSON(hash) | |
JSON.parse(json) | |
end | |
end | |
end |
Author
thejspr
commented
Feb 25, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment