Created
November 11, 2014 11:27
-
-
Save alexesDev/ae684996cdfc7c2dc4f7 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 'arbre' | |
require 'benchmark' | |
def generate_html | |
Arbre::Context.new do | |
10000.times do |i| | |
div class: 'article' do | |
div "Article #{i}", class: 'article__title' | |
div "Awesome content", class: 'article__content' | |
end | |
end | |
end | |
end | |
def patch | |
Arbre::Element.class_eval do | |
def add_child(child) | |
return unless child | |
if child.is_a?(Array) | |
child.each{|item| add_child(item) } | |
return @children | |
end | |
unless child.is_a?(Arbre::Element) | |
child = Arbre::HTML::TextNode.from_string(child) | |
end | |
if child.respond_to?(:parent) | |
child.parent.remove_child(child) if child.parent and child.parent != self | |
child.parent = self | |
end | |
@children << child | |
end | |
end | |
end | |
Benchmark.bm do |x| | |
x.report { generate_html } | |
x.report { patch; generate_html } | |
end |
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
$ ruby test.rb | |
user system total real | |
2.870000 0.010000 2.880000 ( 2.877290) | |
0.340000 0.000000 0.340000 ( 0.348035) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment