Created
February 28, 2010 15:08
-
-
Save julik/317624 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "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