Skip to content

Instantly share code, notes, and snippets.

@alexesDev
Last active May 22, 2019 20:36
Show Gist options
  • Save alexesDev/343e22b45fac02fd7f509bb408874f66 to your computer and use it in GitHub Desktop.
Save alexesDev/343e22b45fac02fd7f509bb408874f66 to your computer and use it in GitHub Desktop.
require 'arbre'
require 'benchmark'
def generate_html
context = Arbre::Context.new do
100000.times do |i|
div class: 'article' do
div "Article #{i}", class: 'article__title'
div "Awesome content", class: 'article__content'
end
end
end
context.to_s
end
if ENV['APPLY_PATCH']
Arbre::HTML::Tag.class_eval do
def indent(open_tag, child_content, close_tag)
open_tag + child_content + close_tag
end
end
end
Benchmark.bmbm do |x|
x.report { generate_html }
end

$ ruby arbre_benchmark.rb

Rehearsal ------------------------------------
   6.358706   0.182712   6.541418 (  6.555321)
--------------------------- total: 6.541418sec

       user     system      total        real
   5.747130   0.016499   5.763629 (  5.776037)

$ APPLY_PATCH=yes ruby arbre_benchmark.rb

Rehearsal ------------------------------------
   5.964307   0.156302   6.120609 (  6.127731)
--------------------------- total: 6.120609sec

       user     system      total        real
   5.192958   0.003310   5.196268 (  5.202189)

5.192958/5.747130 = 10%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment