Created
October 1, 2008 21:24
-
-
Save tenderlove/14196 to your computer and use it in GitHub Desktop.
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 '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