forked from mustache/mustache
/
speed.rb
76 lines (59 loc) · 1.49 KB
/
speed.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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)
scope = ComplexView.new.send(:binding)
bench 'ERB w/ caching' do
erb.result(scope)
end
unless ENV['CACHED']
scope = ComplexView.new.send(:binding)
bench 'ERB w/o caching' do
ERB.new(template).result(scope)
end
end
end
## haml
require 'haml'
template = File.read(File.dirname(__FILE__) + '/complex.haml')
unless ENV['NOHAML']
haml = Haml::Engine.new(template)
scope = ComplexView.new.send(:binding)
bench 'HAML w/ caching' do
haml.render(scope)
end
unless ENV['CACHED']
scope = ComplexView.new.send(:binding)
bench 'HAML w/o caching' do
Haml::Engine.new(template).render(scope)
end
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
ctpl = ComplexView.new
ctpl.template = content
ctpl[:item] = items
ctpl.to_html
end
end