Skip to content

Instantly share code, notes, and snippets.

@billdueber
Created October 25, 2010 20:26
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 billdueber/645683 to your computer and use it in GitHub Desktop.
Save billdueber/645683 to your computer and use it in GitHub Desktop.
Deserialization speed of marc-in-json vs marcxml under ruby-marc with fastest available libraries
require 'rubygems'
require 'marc'
require 'yajl'
require 'benchmark'
iterations = 5
xmlsourcefile = 'topics.xml' # 18k records as a MARC-XML collection
jsonsourcefile = 'topics.ndj' # Same records as newline-delimited marc-in-json
Benchmark.bm do |x|
x.report("xml w/libxml") do
iterations.times do
reader = MARC::XMLReader.new(xmlsourcefile, :parser=>'libxml')
reader.each do |r|
title = r['245']
end
end
end
x.report("marc-in-json w/yajl") do
iterations.times do
File.open(jsonsourcefile).each_line do |json|
r = MARC::Record.new_from_hash(Yajl::Parser.parse(json))
title = r['245']
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment