Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created October 1, 2008 20:40
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/14187 to your computer and use it in GitHub Desktop.
Save tenderlove/14187 to your computer and use it in GitHub Desktop.
require 'nokogiri'
require 'rubygems'
require 'builder'
require 'benchmark'
n = 50_000
Benchmark.bm(7) do |x|
x.report("builder: ") {
n.times {
builder = Builder::XmlMarkup.new(:indent => 1)
builder.instruct!
builder.root {
builder.hello("World!", "type" => "global")
}
}
}
x.report("nokogiri: ") {
n.times {
Nokogiri::XML::Builder.new {
root {
hello(:type => "global") {
text "World!"
}
}
}.to_xml
}
}
end
__END__
user system total real
builder: 9.570000 0.030000 9.600000 ( 9.695058)
nokogiri: 3.840000 0.020000 3.860000 ( 3.878262)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment