Created
February 14, 2013 22:03
-
-
Save kyledrake/4956808 to your computer and use it in GitHub Desktop.
Testing different binary protocol implementations
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
require 'json' | |
require 'bson' | |
require 'msgpack' | |
require 'benchmark' | |
#require 'ruby_protobuf' | |
test_hash = {'string' => 'test string', 'float' => 5} | |
json_results = Benchmark.measure do | |
100_000.times do | |
@test_one = test_hash.to_json | |
end | |
end | |
puts "JSON: #{json_results}" | |
puts "JSON Length: #{@test_one.bytesize}" | |
bson_results = Benchmark.measure do | |
100_000.times do | |
@test_one = BSON.serialize(test_hash).to_s | |
end | |
end | |
puts "BSON: #{bson_results}" | |
puts "BSON Length: #{@test_one.bytesize}" | |
msgpack_results = Benchmark.measure do | |
100_000.times do | |
@test_one = test_hash.to_msgpack | |
end | |
end | |
puts "MessagePack: #{msgpack_results}" | |
puts "MessagePack Length: #{@test_one.bytesize}" | |
=begin | |
JSON: 1.000000 0.000000 1.000000 ( 1.007621) | |
BSON: 0.590000 0.000000 0.590000 ( 0.587634) | |
MessagePack: 0.160000 0.010000 0.170000 ( 0.169203) | |
JSON Length: 34 | |
BSON Length: 40 | |
MessagePack Length: 27 | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment