Skip to content

Instantly share code, notes, and snippets.

@owenthereal
Last active December 16, 2015 15:29
Show Gist options
  • Save owenthereal/5456388 to your computer and use it in GitHub Desktop.
Save owenthereal/5456388 to your computer and use it in GitHub Desktop.
Benchmark of serialization with msgpack (https://github.com/msgpack/msgpack-ruby) vesus Oj (the fatest JSON library https://github.com/ohler55/oj)
require 'benchmark'
h = { 'one' => 1, 'array' => [ true, false ] }
n = 50000
require 'oj'
Benchmark.bmbm do |x|
x.report('Oj.dump') { n.times { Oj.dump(h) } }
end
h_dump = Oj.dump(h)
Benchmark.bmbm do |x|
x.report('Oj.load') { n.times { Oj.load(h_dump) } }
end
require 'msgpack'
Benchmark.bmbm do |x|
x.report('to_msgpack') { n.times { h.to_msgpack } }
end
h_dump = h.to_msgpack
Benchmark.bmbm do |x|
x.report('MessagePack.unpack') { n.times { MessagePack.unpack(h_dump) } }
end
# Rehearsal -------------------------------------------
# Oj.dump 0.790000 0.000000 0.790000 ( 0.790353)
# ---------------------------------- total: 0.790000sec
# user system total real
# Oj.dump 0.760000 0.000000 0.760000 ( 0.767639)
#
# Rehearsal -------------------------------------------
# Oj.load 0.090000 0.000000 0.090000 ( 0.094122)
# ---------------------------------- total: 0.090000sec
#
# user system total real
# Oj.load 0.080000 0.010000 0.090000 ( 0.091066)
#
# Rehearsal ----------------------------------------------
# to_msgpack 0.040000 0.010000 0.050000 ( 0.040576)
# ------------------------------------- total: 0.050000sec
#
# user system total real
# to_msgpack 0.030000 0.000000 0.030000 ( 0.036711)
#
# Rehearsal ------------------------------------------------------
# MessagePack.unpack 0.080000 0.000000 0.080000 ( 0.075730)
# ---------------------------------------------- total: 0.080000sec
#
# user system total real
# MessagePack.unpack 0.070000 0.000000 0.070000 ( 0.063036)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment