Skip to content

Instantly share code, notes, and snippets.

@groyoh
Created June 20, 2016 09:46
Show Gist options
  • Save groyoh/b6dfd1cd8a2442636f08fc0802206905 to your computer and use it in GitHub Desktop.
Save groyoh/b6dfd1cd8a2442636f08fc0802206905 to your computer and use it in GitHub Desktop.
JrJackson vs Active Support vs GSON vs pure json
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "benchmark-ips", require: "benchmark/ips"
gem "jrjackson"
gem "gson"
gem "activesupport", require: "active_support/all"
end
require "json"
H = {
a: {
b: {
c: [1,2,3,4,5],
d: 1.4,
e: :f,
g: "abcdfesfgsegsegsegsegsegeges"
}
}
}.freeze
Benchmark.ips do |x|
x.warmup = 20
x.report("JRjackson") do
JrJackson::Json.dump(H)
end
x.report("AS") do
H.to_json
end
x.report("gson") do
Gson::Encoder.new.encode(H)
end
x.report("json") do
JSON.generate(H)
end
x.compare!
end
__END__
Warming up --------------------------------------
JRjackson 48.792k i/100ms
AS 4.446k i/100ms
gson 43.213k i/100ms
json 23.096k i/100ms
Calculating -------------------------------------
JRjackson 783.292k (± 3.7%) i/s - 3.952M
AS 53.123k (± 3.9%) i/s - 266.760k
gson 552.541k (± 5.6%) i/s - 2.766M
json 277.943k (± 3.8%) i/s - 1.409M
Comparison:
JRjackson: 783292.4 i/s
gson: 552541.4 i/s - 1.42x slower
json: 277943.2 i/s - 2.82x slower
AS: 53122.6 i/s - 14.75x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment