Skip to content

Instantly share code, notes, and snippets.

@kaiwren
Created September 15, 2011 11:15
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 kaiwren/1219023 to your computer and use it in GitHub Desktop.
Save kaiwren/1219023 to your computer and use it in GitHub Desktop.
Json gem vs. Json pure
require 'rubygems'
require 'multi_json'
require 'benchmark'
n = 100000
json = "{\"ids_shop\":[],\"ids_collection\":[],\"ids_wish_list\":[]}"
Benchmark.bmbm do |x|
# x.report("json") do
# MultiJson.engine = :json_gem
# n.times { MultiJson.decode(json) }
# end
x.report("json pure") do
MultiJson.engine = :json_pure
n.times { MultiJson.decode(json) }
end
end
# Rehearsal ---------------------------------------------
# json pure 5.260000 0.010000 5.270000 ( 5.267665)
# ------------------------------------ total: 5.270000sec
#
# user system total real
# json pure 5.300000 0.020000 5.320000 ( 5.308652)
# Rehearsal ----------------------------------------
# json 0.760000 0.020000 0.780000 ( 0.786621)
# ------------------------------- total: 0.780000sec
#
# user system total real
# json 0.750000 0.030000 0.780000 ( 0.770398)
# copy output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment