Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created October 1, 2008 21:24
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 tenderlove/14196 to your computer and use it in GitHub Desktop.
Save tenderlove/14196 to your computer and use it in GitHub Desktop.
require 'nokogiri'
require 'rubygems'
require 'benchmark'
require 'faster_builder/xml_markup'
n = 50_000
Benchmark.bm(7) do |x|
x.report("nokogiri: ") {
n.times {
Nokogiri::XML::Builder.new {
root {
hello(:type => "global") {
text "World!"
}
100.times { |num|
self.send(:"#{num}", num.to_s)
}
}
}.to_xml
}
}
x.report("faster builder: ") {
n.times {
builder = FasterBuilder::XmlMarkup.new(:indent => 1)
builder.instruct!
builder.root {
builder.hello("World!", "type" => "global")
100.times { |num|
builder.send(:"#{num}", num.to_s)
}
}
builder.target!
}
}
end
__END__
user system total real
nokogiri: 67.130000 0.380000 67.510000 ( 69.584561)
faster builder: 92.750000 0.530000 93.280000 ( 95.785319)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment