Add a benchmark for capture vs. assign in Liquid. [ci skip]

This commit is contained in:
Parker Moore 2016-06-21 14:20:18 -07:00
parent 1779aa681a
commit b539c32364
No known key found for this signature in database
GPG Key ID: 193CDEBA72063C58
1 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,20 @@
require "liquid"
require "benchmark/ips"
puts "Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
puts "Liquid #{Liquid::VERSION}"
template1 = '{% capture foobar %}foo{{ bar }}{% endcapture %}{{ foo }}{{ foobar }}'
template2 = '{% assign foobar = "foo" | append: bar %}{{ foobar }}'
def render(template)
Liquid::Template.parse(template).render("bar" => "42")
end
puts render(template1)
puts render(template2)
Benchmark.ips do |x|
x.report('capture') { render(template1) }
x.report('assign') { render(template2) }
end