Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'benchmark'
- require 'examples/complex_view'
- class Handlebar < ComplexView
- def render_sections(template)
- # fail fast
- return template unless template.include?('{{#')
- template.gsub(/\{\{\#([^\}]*)\}\}\s*(.+)\{\{\/\1\}\}\s*/m) do |s|
- ret = find($1)
- if ret.respond_to? :each
- ret.map do |ctx|
- render($2, ctx)
- end.join
- elsif ret
- render($2)
- else
- ''
- end
- end
- end
- end
- n = 10000
- Benchmark.bm(9) do |x|
- x.report('complex') { n.times { ComplexView.to_html } }
- x.report('handlebar') { n.times { Handlebar.to_html } }
- end
- __END__
- user system total real
- complex 18.760000 0.710000 19.470000 ( 26.253526)
- handlebar 6.320000 0.520000 6.840000 ( 12.494350)
Add Comment
Please, Sign In to add comment