Skip to content

Instantly share code, notes, and snippets.

@lacrosse
Last active August 29, 2015 14:23
Show Gist options
  • Save lacrosse/93d5eb2ebc95f4f311df to your computer and use it in GitHub Desktop.
Save lacrosse/93d5eb2ebc95f4f311df to your computer and use it in GitHub Desktop.
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