Sha256: d6387300b816bd648b7697401250a7929efd31db8b8cd1c64a10f76a99747471

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'erb'

$LOAD_PATH.unshift File.dirname(__FILE__)
require 'helper'

$LOAD_PATH.unshift File.dirname(__FILE__) + '/../examples'
require 'complex_view'

## erb
template = File.read(File.dirname(__FILE__) + '/complex.erb')

unless ENV['NOERB']
  erb =  ERB.new(template)
  bench 'ERB w/ caching' do
    erb.result(ComplexView.new.send(:binding))
  end

  bench 'ERB w/o caching' do
    ERB.new(template).result(ComplexView.new.send(:binding))
  end
end

## mustache
tpl = ComplexView.new
tpl.template

tpl[:header] = 'Chris'
tpl[:empty] = false
tpl[:list] = true

items = []
items << { :name => 'red', :current => true, :url => '#Red' }
items << { :name => 'green', :current => false, :url => '#Green' }
items << { :name => 'blue', :current => false, :url => '#Blue' }

tpl[:item] = items

bench '{ w/ caching' do
  tpl.to_html
end

content = File.read(ComplexView.template_file)

unless ENV['CACHED']
  bench '{ w/o caching' do
    tpl = ComplexView.new
    tpl.template = content
    tpl[:item] = items
    tpl.to_html
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mustache-0.2.0 benchmarks/speed.rb