Skip to content

Instantly share code, notes, and snippets.

@ccocchi
Created March 27, 2017 07:42
Show Gist options
  • Save ccocchi/856403d8c47a9d4c6beacf7834db3bc8 to your computer and use it in GitHub Desktop.
Save ccocchi/856403d8c47a9d4c6beacf7834db3bc8 to your computer and use it in GitHub Desktop.
require 'active_support/concern'
require 'active_support/core_ext/object/blank'
require 'action_view/buffers'
require 'action_view/helpers/output_safety_helper'
require 'action_view/helpers/capture_helper'
require 'action_view/helpers/tag_helper'
require 'benchmark/ips'
class Bench
include ActionView::Helpers::TagHelper
attr_accessor :output_buffer
def with_block
content_tag(:div, class: 'foo bar foo-bar') do
'<i class="fa fa-euro"></i>'
end
end
def inline
content_tag(:div, '<i class="fa fa-euro"></i>', class: 'foo bar foo-bar')
end
end
Benchmark.ips do |x|
x.report('block') { Bench.new.with_block }
x.report('inline') { Bench.new.inline }
x.compare!
end
@ccocchi
Copy link
Author

ccocchi commented Mar 27, 2017

Warming up --------------------------------------
               block     4.227k i/100ms
              inline     6.647k i/100ms
Calculating -------------------------------------
               block     44.456k (± 3.9%) i/s -    224.031k in   5.047405s
              inline     68.414k (± 4.4%) i/s -    345.644k in   5.062369s

Comparison:
              inline:    68413.5 i/s
               block:    44455.6 i/s - 1.54x slower

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