Created
October 25, 2010 20:26
-
-
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
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 '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