Skip to content

Instantly share code, notes, and snippets.

@ouranos
Forked from havenwood/benchmark_results.rb
Last active May 30, 2017 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ouranos/cd99ae98c23d7f9c596ff3ac732832bb to your computer and use it in GitHub Desktop.
Save ouranos/cd99ae98c23d7f9c596ff3ac732832bb to your computer and use it in GitHub Desktop.
Benchmarking serialization speed of YAML, JSON, Marshal, and MessagePack in Ruby, JRuby, and Rubinius
# ruby 2.3.3p222
user system total real
YAML 31.860000 0.000000 31.860000 ( 31.886926)
JSON 1.370000 0.000000 1.370000 ( 1.374081)
Marshal 0.710000 0.000000 0.710000 ( 0.711384)
MessagePack 0.510000 0.000000 0.510000 ( 0.505674)
# jruby 9.1.7.0 (2.3.1)
user system total real
YAML 26.270000 0.040000 26.310000 ( 25.652204)
JSON 0.740000 0.010000 0.750000 ( 0.741911)
Marshal 0.500000 0.000000 0.500000 ( 0.504016)
MessagePack 0.360000 0.000000 0.360000 ( 0.356285)
# ruby 2.4.0p0
user system total real
YAML 28.370000 0.010000 28.380000 ( 28.396227)
JSON 1.230000 0.000000 1.230000 ( 1.227030)
Marshal 0.720000 0.000000 0.720000 ( 0.713398)
MessagePack 0.470000 0.000000 0.470000 ( 0.468230)
require 'benchmark'
require 'yaml'
require 'json'
require 'msgpack'
Benchmark.bmbm do |bm|
this_many = 100_000
this = {aim: true,
nested: {number: 100_000_000,
string: 'my life close twice before...'}}
bm.report 'YAML' do
this_many.times do
YAML.load YAML.dump(this)
end
end
bm.report 'JSON' do
this_many.times do
JSON.parse JSON.generate(this)
end
end
bm.report 'Marshal' do
this_many.times do
Marshal.load Marshal.dump(this)
end
end
bm.report 'MessagePack' do
this_many.times do
MessagePack.unpack MessagePack.pack(this)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment