Skip to content

Instantly share code, notes, and snippets.

@billdueber
Created July 31, 2012 04:44
Show Gist options
  • Save billdueber/3213716 to your computer and use it in GitHub Desktop.
Save billdueber/3213716 to your computer and use it in GitHub Desktop.
JRuby JSON-generation slowdown benchmark
require 'benchmark'
require 'json'
puts RUBY_DESCRIPTION
# This mess is a json representation of a MARC record (format used in libraries and museums)
m = %Q[{"leader":"01470nam^a22004451^^4500","fields":[{"001":"000000040"},{"005":"19880715000000.0"},{"006":"m^^^^^^^^d^^^^^^^^"},{"007":"cr^bn^---auaua"},{"008":"880715s1968^^^^nyuae^^^^b^^^|00100^eng^^"},{"010":{"ind1":" ","ind2":" ","subfields":[{"a":"68027371"}]}},{"035":{"ind1":" ","ind2":" ","subfields":[{"a":"(RLIN)MIUG0001728-B"}]}},{"035":{"ind1":" ","ind2":" ","subfields":[{"a":"(CaOTULAS)159818044"}]}},{"035":{"ind1":" ","ind2":" ","subfields":[{"a":"(OCoLC)ocm00001728"}]}},{"040":{"ind1":" ","ind2":" ","subfields":[{"a":"DLC"},{"c":"DLC"},{"d":"MiU"},{"d":"CStRLIN"},{"d":"MiU"}]}},{"050":{"ind1":"0","ind2":" ","subfields":[{"a":"N6350"},{"b":".P4 1968b"}]}},{"082":{"ind1":" ","ind2":" ","subfields":[{"a":"709.03"}]}},{"100":{"ind1":"1","ind2":" ","subfields":[{"a":"Pevsner, Nikolaus,"},{"d":"1902-1983."}]}},{"245":{"ind1":"1","ind2":"0","subfields":[{"a":"Studies in art, architecture, and design."}]}},{"260":{"ind1":" ","ind2":" ","subfields":[{"a":"New York,"},{"b":"Walker"},{"c":"[1968]"}]}},{"300":{"ind1":" ","ind2":" ","subfields":[{"a":"2 v."},{"b":"illus., plans."},{"c":"30 cm."}]}},{"504":{"ind1":" ","ind2":" ","subfields":[{"a":"Includes bibliographical references."}]}},{"505":{"ind1":"0","ind2":" ","subfields":[{"a":"v. 1. From mannerism to romanticism.--v. 2. Victorian and after."}]}},{"538":{"ind1":" ","ind2":" ","subfields":[{"a":"Mode of access: Internet."}]}},{"650":{"ind1":" ","ind2":"0","subfields":[{"a":"Art"},{"x":"History"}]}},{"852":{"ind1":"0","ind2":" ","subfields":[{"a":"MiU"},{"b":"BUHR"},{"c":"AAEL"},{"h":"N 5303 .P52 1968"}]}},{"852":{"ind1":"0","ind2":" ","subfields":[{"a":"MiU"},{"b":"AAEL"},{"c":"BKS"},{"h":"N 5303 .P52 1968"}]}},{"970":{"ind1":" ","ind2":" ","subfields":[{"a":"BK"},{"b":"Book"}]}},{"970":{"ind1":" ","ind2":" ","subfields":[{"a":"CE"},{"b":"Electronic Resource"}]}},{"971":{"ind1":" ","ind2":" ","subfields":[{"a":"MiU"}]}},{"972":{"ind1":" ","ind2":" ","subfields":[{"c":"20040625"}]}},{"972":{"ind1":" ","ind2":" ","subfields":[{"c":"20040625"}]}},{"973":{"ind1":" ","ind2":" ","subfields":[{"a":"HT"},{"b":"avail_ht"}]}},{"973":{"ind1":" ","ind2":" ","subfields":[{"a":"AC"},{"b":"avail_circ"}]}},{"974":{"ind1":" ","ind2":" ","subfields":[{"z":"v.1"},{"u":"mdp.39015005817484"},{"r":"ic"}]}},{"974":{"ind1":" ","ind2":" ","subfields":[{"z":"v.1"},{"u":"mdp.39015006324134"},{"r":"ic"}]}},{"974":{"ind1":" ","ind2":" ","subfields":[{"z":"v.2"},{"u":"mdp.39015006324142"},{"r":"ic"},{"d":"20090907"}]}},{"974":{"ind1":" ","ind2":" ","subfields":[{"z":"v.2"},{"u":"mdp.39015007230850"},{"r":"ic"},{"d":"20091119"}]}},{"998":{"ind1":" ","ind2":" ","subfields":[{"c":"GAC"},{"s":"9125"}]}},{"995":{"ind1":" ","ind2":" ","subfields":[{"a":"form"},{"b":"form character life trend modern merely self world romantic attitude nature expression element mean principle"},{"c":"761"}]}}]}]
# Turn it into a hash
h = JSON.parse(m)
iters = 1_000
Benchmark.bm do |x|
x.report do
iters.times do
JSON.fast_generate(h)
end
end
end
#jruby 1.6.7.2 (ruby-1.9.2-p312) (2012-05-01 26e08ba) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_31) [darwin-x86_64-java]
# user system total real
# 0.307000 0.000000 0.307000 ( 0.308000)
#jruby 1.7.0.preview2.dev (ruby-1.9.3-p203) (2012-07-29 b9e669b) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_31) [darwin-x86_64-java]
# user system total real
#130.150000 2.260000 132.410000 (128.419000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment