-
-
Save mjc/9531419 to your computer and use it in GitHub Desktop.
Message format benchmarks
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
$data = { | |
"repository" => { | |
"watchers" => 173, | |
"has_wiki" => true, | |
"url" => "https://github.com/flori/json", | |
"open_issues" => 21, | |
"homepage" => "http://flori.github.com/json", | |
"has_issues" => true, | |
"forks" => 35, | |
"fork" => false, | |
"language" => "Ruby", | |
"integrate_branch" => "master", | |
"created_at" => "2009/08/24 15:21:39 -0700", | |
"master_branch" => "master", | |
"size" => 572, | |
"private" => false, | |
"name" => "json", | |
"owner" => "flori", | |
"has_downloads" => true, | |
"pushed_at" => "2011/07/08 07:34:34 -0700", | |
"description" => "JSON implementation for Ruby" | |
} | |
} |
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 'rubygems' | |
require 'bundler/setup' | |
Bundler.require | |
require './data' | |
data = JSON.dump($data) | |
marshal_data = Marshal.dump($data) | |
Benchmark.ips do |x| | |
x.report("Marshal.dump") { Marshal.load(marshal_data) } | |
x.report("JSON.dump") { JSON.parse(data) } | |
MultiJson.use :json_gem | |
x.report("MultiJSON (JSON)") { MultiJson.load(data) } | |
if defined?(Oj) | |
x.report("Oj") { Oj.load(data) } | |
x.report("Oj compat") { Oj.load(data,mode: :compat) } | |
MultiJson.use :oj | |
x.report("MultiJSON (Oj)") { MultiJson.load(data) } | |
end | |
if defined?(Yajl) | |
x.report("Yajl") { Yajl::Parser.new.parse(data) } | |
MultiJson.use :yajl | |
x.report("MultiJSON (Yajl)") { MultiJson.load(data) } | |
end | |
if defined?(OkJson) | |
MultiJson.use :ok_json | |
x.report("MultiJSON (Ok)") { MultiJson.load(data) } | |
end | |
if defined?(JrJackson) | |
x.report("JrJackson") { JrJackson::Json.load(data) } | |
MultiJson.use :jrjackson | |
x.report("MultiJSON (JrJackson)") { MultiJson.load(data) } | |
end | |
if defined?(Gson) | |
x.report("Gson.new.encode") { Gson::Decoder.new.decode(data) } | |
gson = Gson::Decoder.new | |
x.report("gson.encode") { gson.Decode(data) } | |
MultiJson.use :gson | |
x.report("MultiJSON (Gson)") { MultiJson.load(data) } | |
end | |
end |
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'bundler/setup' | |
Bundler.require | |
require './data' | |
if ["jruby","rbx"].include?(RUBY_ENGINE) | |
puts "Warming up the JIT" | |
warmup = 250_000 | |
data = $data.dup | |
warmup.times { | |
Marshal.dump(data) | |
JSON.dump(data) | |
MultiJson.use :json_gem | |
MultiJson.dump(data) | |
if defined?(Oj) | |
Oj.dump(data) | |
Oj.dump(data, mode: :compat) | |
MultiJson.use :oj | |
MultiJson.dump(data) | |
end | |
if defined?(Yajl) | |
Yajl::Encoder.encode(data) | |
MultiJson.use :yajl | |
MultiJson.dump(data) | |
end | |
if defined?(JrJackson) | |
JrJackson::Json.dump(data) | |
MultiJson.use :jrjackson | |
MultiJson.dump(data) | |
end | |
if defined?(Gson) | |
Gson::Encoder.new.encode(data) | |
MultiJson.use :gson | |
MultiJson.dump(data) | |
end | |
} | |
puts "JIT is warm." | |
end | |
Bundler.require | |
Benchmark.ips do |x| | |
data = $data.dup | |
x.report("Marshal.dump") { Marshal.dump(data) } | |
x.report("JSON.dump") { JSON.dump(data) } | |
MultiJson.use :json_gem | |
x.report("MultiJSON (JSON)") { MultiJson.dump(data) } | |
if defined?(Oj) | |
x.report("Oj") { Oj.dump(data) } | |
x.report("Oj compat") { Oj.dump(data,mode: :compat) } | |
MultiJson.use :oj | |
x.report("MultiJSON (Oj)") { MultiJson.dump(data) } | |
end | |
if defined?(Yajl) | |
x.report("Yajl") { Yajl::Encoder.encode(data) } | |
MultiJson.use :yajl | |
x.report("MultiJSON (Yajl)") { MultiJson.dump(data) } | |
end | |
if defined?(OkJson) | |
MultiJson.use :ok_json | |
x.report("MultiJSON (Ok)") { MultiJson.dump(data) } | |
end | |
if defined?(JrJackson) | |
x.report("JrJackson") { JrJackson::Json.dump(data) } | |
MultiJson.use :jrjackson | |
x.report("MultiJSON (JrJackson)") { MultiJson.dump(data) } | |
end | |
if defined?(Gson) | |
x.report("Gson.new.encode") { Gson::Encoder.new.encode(data) } | |
gson = Gson::Encoder.new | |
x.report("gson.encode") { gson.encode(data) } | |
MultiJson.use :gson | |
x.report("MultiJSON (Gson)") { MultiJson.dump(data) } | |
end | |
end |
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
Calculating ------------------------------------- | |
Marshal.dump 3708 i/100ms | |
JSON.dump 6353 i/100ms | |
MultiJSON (JSON) 8827 i/100ms | |
Oj 34758 i/100ms | |
Oj compat 28611 i/100ms | |
MultiJSON (Oj) 9102 i/100ms | |
Yajl 11776 i/100ms | |
MultiJSON (Yajl) 9102 i/100ms | |
------------------------------------------------- | |
Marshal.dump 37754.0 (±5.7%) i/s - 189108 in 5.027165s | |
JSON.dump 66753.4 (±3.5%) i/s - 336709 in 5.050683s | |
MultiJSON (JSON) 96484.1 (±6.1%) i/s - 485485 in 5.053139s | |
Oj 433018.0 (±11.1%) i/s - 2154996 in 5.039276s | |
Oj compat 323045.0 (±6.1%) i/s - 1630827 in 5.066927s | |
MultiJSON (Oj) 97169.1 (±4.0%) i/s - 491508 in 5.066476s | |
Yajl 126062.8 (±6.3%) i/s - 635904 in 5.067090s | |
MultiJSON (Yajl) 99258.1 (±3.3%) i/s - 500610 in 5.049149s |
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
Warming up the JIT | |
JIT is warm. | |
Calculating ------------------------------------- | |
Marshal.dump 7527 i/100ms | |
JSON.dump 11606 i/100ms | |
MultiJSON (JSON) 8796 i/100ms | |
JrJackson 10670 i/100ms | |
MultiJSON (JrJackson) | |
8665 i/100ms | |
Gson.new.encode 9064 i/100ms | |
gson.encode 9573 i/100ms | |
MultiJSON (Gson) 8637 i/100ms | |
------------------------------------------------- | |
Marshal.dump 83433.7 (±3.4%) i/s - 421512 in 5.057999s | |
JSON.dump 128006.3 (±4.0%) i/s - 638330 in 4.995000s | |
MultiJSON (JSON) 96071.4 (±2.9%) i/s - 483780 in 5.040000s | |
JrJackson 111926.0 (±4.6%) i/s - 565510 in 5.064000s | |
MultiJSON (JrJackson) | |
96271.7 (±2.7%) i/s - 485240 in 5.044000s | |
Gson.new.encode 99084.2 (±7.9%) i/s - 498520 in 5.067000s | |
gson.encode 100974.7 (±3.3%) i/s - 507369 in 5.030000s | |
MultiJSON (Gson) 95405.4 (±3.7%) i/s - 483672 in 5.077000s |
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
Warming up the JIT | |
JIT is warm. | |
Calculating ------------------------------------- | |
Marshal.dump 7753 i/100ms | |
JSON.dump 11127 i/100ms | |
MultiJSON (JSON) 9081 i/100ms | |
JrJackson 11077 i/100ms | |
MultiJSON (JrJackson) | |
8640 i/100ms | |
Gson.new.encode 10132 i/100ms | |
gson.encode 10299 i/100ms | |
MultiJSON (Gson) 8886 i/100ms | |
------------------------------------------------- | |
Marshal.dump 81010.3 (±3.0%) i/s - 410909 in 5.077000s | |
JSON.dump 117032.0 (±3.4%) i/s - 589731 in 5.045000s | |
MultiJSON (JSON) 94636.8 (±2.5%) i/s - 481293 in 5.089000s | |
JrJackson 114647.2 (±4.1%) i/s - 576004 in 5.033000s | |
MultiJSON (JrJackson) | |
95725.9 (±2.2%) i/s - 483840 in 5.057000s | |
Gson.new.encode 105672.3 (±2.9%) i/s - 536996 in 5.086000s | |
gson.encode 102529.2 (±4.7%) i/s - 514950 in 5.034000s | |
MultiJSON (Gson) 91534.8 (±3.1%) i/s - 462072 in 5.053000s |
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
Warming up the JIT | |
JIT is warm. | |
Calculating ------------------------------------- | |
Marshal.dump 6834 i/100ms | |
JSON.dump 15104 i/100ms | |
MultiJSON (JSON) 9042 i/100ms | |
JrJackson 14909 i/100ms | |
MultiJSON (JrJackson) | |
9506 i/100ms | |
Gson.new.encode 12100 i/100ms | |
gson.encode 11988 i/100ms | |
MultiJSON (Gson) 9115 i/100ms | |
------------------------------------------------- | |
Marshal.dump 76758.5 (±3.2%) i/s - 389538 in 5.080000s | |
JSON.dump 187706.5 (±3.9%) i/s - 936448 in 4.997999s | |
MultiJSON (JSON) 111458.6 (±2.5%) i/s - 560604 in 5.033000s | |
JrJackson 180275.9 (±3.5%) i/s - 909449 in 5.051000s | |
MultiJSON (JrJackson) | |
110316.3 (±2.5%) i/s - 551348 in 5.001000s | |
Gson.new.encode 139274.4 (±4.1%) i/s - 701800 in 5.048000s | |
gson.encode 140045.5 (±3.8%) i/s - 707292 in 5.058000s | |
MultiJSON (Gson) 109736.3 (±3.4%) i/s - 556015 in 5.073000s |
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
Warming up the JIT | |
JIT is warm. | |
Calculating ------------------------------------- | |
Marshal.dump 6429 i/100ms | |
JSON.dump 10978 i/100ms | |
MultiJSON (JSON) 6851 i/100ms | |
JrJackson 12480 i/100ms | |
MultiJSON (JrJackson) | |
7680 i/100ms | |
Gson.new.encode 11819 i/100ms | |
gson.encode 11847 i/100ms | |
MultiJSON (Gson) 7679 i/100ms | |
------------------------------------------------- | |
Marshal.dump 74400.9 (±2.9%) i/s - 372882 in 5.016000s | |
JSON.dump 144188.5 (±3.1%) i/s - 724548 in 5.030000s | |
MultiJSON (JSON) 88782.2 (±2.9%) i/s - 445315 in 5.020000s | |
JrJackson 166498.4 (±3.1%) i/s - 836160 in 5.027000s | |
MultiJSON (JrJackson) | |
88316.9 (±3.8%) i/s - 445440 in 5.051000s | |
Gson.new.encode 149633.8 (±2.4%) i/s - 756416 in 5.058000s | |
gson.encode 154242.8 (±2.3%) i/s - 781902 in 5.072000s | |
MultiJSON (Gson) 89040.1 (±2.8%) i/s - 445382 in 5.006000s |
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
Warming up the JIT | |
JIT is warm. | |
Calculating ------------------------------------- | |
Marshal.dump 6636 i/100ms | |
JSON.dump 15599 i/100ms | |
MultiJSON (JSON) 9622 i/100ms | |
JrJackson 14025 i/100ms | |
MultiJSON (JrJackson) | |
9588 i/100ms | |
Gson.new.encode 12148 i/100ms | |
gson.encode 12423 i/100ms | |
MultiJSON (Gson) 9795 i/100ms | |
------------------------------------------------- | |
Marshal.dump 73177.3 (±1.8%) i/s - 371616 in 5.080000s | |
JSON.dump 201723.7 (±2.7%) i/s - 1013935 in 5.030000s | |
MultiJSON (JSON) 114309.7 (±2.9%) i/s - 577320 in 5.055000s | |
JrJackson 179738.7 (±2.0%) i/s - 911625 in 5.074000s | |
MultiJSON (JrJackson) | |
115801.5 (±2.2%) i/s - 584868 in 5.053000s | |
Gson.new.encode 147246.0 (±2.6%) i/s - 741028 in 5.036000s | |
gson.encode 152459.8 (±2.0%) i/s - 770226 in 5.054000s | |
MultiJSON (Gson) 115746.1 (±2.2%) i/s - 587700 in 5.080000s |
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
Warming up the JIT | |
JIT is warm. | |
Calculating ------------------------------------- | |
Marshal.dump 6661 i/100ms | |
JSON.dump 12338 i/100ms | |
MultiJSON (JSON) 7590 i/100ms | |
JrJackson 13339 i/100ms | |
MultiJSON (JrJackson) | |
7499 i/100ms | |
Gson.new.encode 12095 i/100ms | |
gson.encode 12554 i/100ms | |
MultiJSON (Gson) 7656 i/100ms | |
------------------------------------------------- | |
Marshal.dump 75967.8 (±1.7%) i/s - 386338 in 5.087000s | |
JSON.dump 146980.0 (±3.2%) i/s - 740280 in 5.042000s | |
MultiJSON (JSON) 86698.4 (±2.2%) i/s - 440220 in 5.080000s | |
JrJackson 165081.0 (±2.5%) i/s - 827018 in 5.013000s | |
MultiJSON (JrJackson) | |
86257.7 (±1.8%) i/s - 434942 in 5.044000s | |
Gson.new.encode 145072.1 (±2.3%) i/s - 725700 in 5.005000s | |
gson.encode 150760.9 (±2.3%) i/s - 753240 in 4.999000s | |
MultiJSON (Gson) 86614.2 (±2.3%) i/s - 436392 in 5.041000s |
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
Warming up the JIT | |
JIT is warm. | |
Calculating ------------------------------------- | |
Marshal.dump 6743 i/100ms | |
JSON.dump 12994 i/100ms | |
MultiJSON (JSON) 8076 i/100ms | |
JrJackson 13812 i/100ms | |
MultiJSON (JrJackson) | |
8053 i/100ms | |
Gson.new.encode 12596 i/100ms | |
gson.encode 12765 i/100ms | |
MultiJSON (Gson) 8144 i/100ms | |
------------------------------------------------- | |
Marshal.dump 75022.8 (±1.9%) i/s - 377608 in 5.035000s | |
JSON.dump 155039.8 (±2.1%) i/s - 779640 in 5.031000s | |
MultiJSON (JSON) 92016.5 (±2.1%) i/s - 460332 in 5.005000s | |
JrJackson 169536.3 (±1.9%) i/s - 856344 in 5.053000s | |
MultiJSON (JrJackson) | |
91771.3 (±2.1%) i/s - 459021 in 5.004000s | |
Gson.new.encode 149427.3 (±2.1%) i/s - 755760 in 5.060000s | |
gson.encode 153010.9 (±1.7%) i/s - 765900 in 5.007000s | |
MultiJSON (Gson) 88834.4 (±3.7%) i/s - 447920 in 5.049000s |
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
Warming up the JIT | |
JIT is warm. | |
Calculating ------------------------------------- | |
Marshal.dump 6806 i/100ms | |
JSON.dump 12206 i/100ms | |
MultiJSON (JSON) 7393 i/100ms | |
JrJackson 13034 i/100ms | |
MultiJSON (JrJackson) | |
7578 i/100ms | |
Gson.new.encode 12049 i/100ms | |
gson.encode 12290 i/100ms | |
MultiJSON (Gson) 7547 i/100ms | |
------------------------------------------------- | |
Marshal.dump 73690.1 (±5.6%) i/s - 367524 in 5.005000s | |
JSON.dump 142761.4 (±4.1%) i/s - 720154 in 5.053000s | |
MultiJSON (JSON) 83041.1 (±4.0%) i/s - 421401 in 5.083000s | |
JrJackson 157597.3 (±3.5%) i/s - 795074 in 5.051000s | |
MultiJSON (JrJackson) | |
82562.0 (±3.9%) i/s - 416790 in 5.056000s | |
Gson.new.encode 140587.3 (±3.6%) i/s - 710891 in 5.062999s | |
gson.encode 145434.3 (±5.2%) i/s - 737400 in 5.085000s | |
MultiJSON (Gson) 79831.9 (±5.1%) i/s - 399991 in 5.024000s |
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
Warming up the JIT | |
JIT is warm. | |
Calculating ------------------------------------- | |
Marshal.dump 375 i/100ms | |
JSON.dump 1864 i/100ms | |
MultiJSON (JSON) 3661 i/100ms | |
Oj 4519 i/100ms | |
Oj compat 3879 i/100ms | |
MultiJSON (Oj) 3684 i/100ms | |
Yajl 4194 i/100ms | |
MultiJSON (Yajl) 3664 i/100ms | |
------------------------------------------------- | |
Marshal.dump 3805.7 (±2.6%) i/s - 19125 in 5.029080s | |
JSON.dump 18926.8 (±2.6%) i/s - 95064 in 5.026014s | |
MultiJSON (JSON) 37744.9 (±3.1%) i/s - 190372 in 5.048592s | |
Oj 46133.2 (±2.7%) i/s - 230469 in 4.999378s | |
Oj compat 39441.6 (±2.7%) i/s - 197829 in 5.019498s | |
MultiJSON (Oj) 38030.2 (±2.7%) i/s - 191568 in 5.041084s | |
Yajl 43786.3 (±2.4%) i/s - 222282 in 5.079497s | |
MultiJSON (Yajl) 38024.6 (±3.2%) i/s - 190528 in 5.015951s |
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
source 'https://rubygems.org' | |
gem 'benchmark-ips' | |
gem 'json' | |
gem 'multi_json' | |
gem 'oj', platform: [:mri, :rbx] | |
gem 'yajl-ruby', platform: [:mri, :rbx], require: 'yajl' | |
gem 'jrjackson', platform: :jruby | |
gem 'gson', platform: :jruby |
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
GEM | |
remote: https://rubygems.org/ | |
specs: | |
benchmark-ips (2.0.0) | |
gson (0.6.1-java) | |
jrjackson (0.2.7) | |
json (1.8.1) | |
json (1.8.1-java) | |
multi_json (1.10.1) | |
oj (2.9.8) | |
yajl-ruby (1.2.1) | |
PLATFORMS | |
java | |
ruby | |
DEPENDENCIES | |
benchmark-ips | |
gson | |
jrjackson | |
json | |
multi_json | |
oj | |
yajl-ruby |
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
#!/bin/bash | |
source /usr/local/share/chruby/chruby.sh | |
chruby 2.1.2 | |
ruby encode.rb | tee encode_2.1.2.txt | |
chruby jruby-1.7.13 | |
JRUBY_OPTS="-Xcompile.mode=JIT -Xcompile.invokedynamic=false" ruby encode.rb | tee encode_jruby-1.7.13-no_indy.txt | |
JRUBY_OPTS="-Xcompile.mode=JIT -Xcompile.invokedynamic=true" ruby encode.rb | tee encode_jruby-1.7.13-indy.txt | |
chruby jruby-head | |
JRUBY_OPTS="-Xcompile.mode=JIT -Xcompile.invokedynamic=false" ruby encode.rb | tee encode_jruby-ir_jit-b620255-no_indy.txt | |
JRUBY_OPTS="-Xcompile.mode=JIT -Xcompile.invokedynamic=true" ruby encode.rb | tee encode_jruby-ir_jit-b620255-indy.txt | |
chruby rbx | |
ruby encode.rb | tee encode_rbx_50466209.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment