Last active
August 29, 2015 14:23
-
-
Save lacrosse/93d5eb2ebc95f4f311df to your computer and use it in GitHub Desktop.
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
require "json" | |
require "msgpack" | |
require "benchmark" | |
hash = { | |
collection: Array.new(ARGV[0].to_i) do | |
{ | |
name: "Stranger in a Room", | |
array: ["this", "that", "and this"], | |
string: "A simple interface to the benchmark method, bm is generates sequential reports with labels." | |
} | |
end | |
} | |
jsoned_hash = hash.to_json | |
msgpacked_hash = hash.to_msgpack | |
n = 25000 | |
Benchmark.bm(20) do |benchmark| | |
benchmark.report("JSON encode") { n.times { JSON.unparse hash } } | |
benchmark.report("MessagePack encode") { n.times { MessagePack.pack hash } } | |
benchmark.report("JSON decode") { n.times { JSON.parse jsoned_hash } } | |
benchmark.report("MessagePack decode") { n.times { MessagePack.unpack msgpacked_hash } } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment