Skip to content

Instantly share code, notes, and snippets.

@billdueber
Created February 13, 2015 18:37
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/7b8e60587e71c2009ced to your computer and use it in GitHub Desktop.
Save billdueber/7b8e60587e71c2009ced to your computer and use it in GitHub Desktop.
FastXMLWriter vs XMLWriter
require 'benchmark'
require 'benchmark/ips'
require 'marc'
require 'marc/fastxmlwriter'
record = MARC::Reader.new('test/one.dat').first
puts RUBY_DESCRIPTION
Benchmark.ips do |x|
x.report('MARC::XMLWriter ') do
str = MARC::XMLWriter.encode(record).to_s
end
x.report("MARC::FastXMLWriter") do
str = MARC::FastXMLWriter.encode(record)
end
x.compare!
end
# ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin13]
#
# Calculating -------------------------------------
# MARC::XMLWriter 32.000 i/100ms
# MARC::FastXMLWriter 570.000 i/100ms
# -------------------------------------------------
# MARC::XMLWriter 326.851 (± 2.1%) i/s - 1.664k
# MARC::FastXMLWriter 5.882k (± 2.0%) i/s - 29.640k
#
# Comparison:
# MARC::FastXMLWriter: 5881.9 i/s
# MARC::XMLWriter : 326.9 i/s - 18.00x slower
#
# =========
#
# jruby 1.7.18 (1.9.3p551) 2014-12-22 625381c on Java HotSpot(TM) 64-Bit Server VM 1.8.0-b132 +jit [darwin-x86_64]
#
# Calculating -------------------------------------
# MARC::XMLWriter 12.000 i/100ms
# MARC::FastXMLWriter 461.000 i/100ms
# -------------------------------------------------
# MARC::XMLWriter 429.220 (±15.6%) i/s - 2.076k
# MARC::FastXMLWriter 8.639k (± 6.2%) i/s - 43.334k
#
# Comparison:
# MARC::FastXMLWriter: 8638.9 i/s
# MARC::XMLWriter : 429.2 i/s - 20.13x slower
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment