Skip to content

Instantly share code, notes, and snippets.

@ursm
Last active Oct 14, 2016
Embed
What would you like to do?
module ApplicationHelper
def tag_helper(i)
content_tag(:foo) {
content_tag(:bar, i)
}
end
def haml_naive(i)
Haml::Engine.new(<<~HAML).render(Object.new, i: i).html_safe
%foo
%bar= i
HAML
end
Haml::Engine.new(<<~HAML).def_method self, :haml_precompiled, :i
%foo
%bar= i
HAML
end
$ bin/rails s -e production
=> Booting Puma
=> Rails 5.0.0.1 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: production
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
user system total real
partial 0.150000 0.020000 0.170000 ( 0.168522)
tag_helper 0.060000 0.000000 0.060000 ( 0.065240)
haml_naive 0.530000 0.000000 0.530000 ( 0.528725)
haml_precompiled 0.030000 0.000000 0.030000 ( 0.026623)
user system total real
partial 0.170000 0.010000 0.180000 ( 0.213928)
tag_helper 0.060000 0.010000 0.070000 ( 0.060891)
haml_naive 0.430000 0.000000 0.430000 ( 0.438646)
haml_precompiled 0.010000 0.000000 0.010000 ( 0.013547)
user system total real
partial 0.150000 0.010000 0.160000 ( 0.157855)
tag_helper 0.070000 0.010000 0.080000 ( 0.074357)
haml_naive 0.460000 0.000000 0.460000 ( 0.470439)
haml_precompiled 0.010000 0.000000 0.010000 ( 0.010962)
- Benchmark.bm 16 do |x|
- x.report 'partial' do
- 1000.times do |i|
= render 'partial', i: i
- x.report 'tag_helper' do
- 1000.times do |i|
= tag_helper i
- x.report 'haml_naive' do
- 1000.times do |i|
= haml_naive i
- x.report 'haml_precompiled' do
- 1000.times do |i|
= haml_precompiled i: i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment