Skip to content

Instantly share code, notes, and snippets.

@julik
Created February 28, 2010 15:08
Show Gist options
  • Save julik/317624 to your computer and use it in GitHub Desktop.
Save julik/317624 to your computer and use it in GitHub Desktop.
require "rubygems"
require "builder"
require "benchmark"
class WithElements < Builder::XmlMarkup
def some_elem(&blk)
self << "<some-elem>"
blk.call(self)
self << "</some-elem>"
end
end
@base = Builder::XmlMarkup.new
@augmented = WithElements.new
def write_elements(into)
1000.times do
into.some_elem do | nest |
nest << "Tekst"
end
end
end
Benchmark.bm do | r |
r.report("with simple XmlBase") do
100.times { write_elements(@base) }
end
r.report("with predefined method") do
100.times { write_elements(@augmented) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment