Repository navigation
Expand file tree
/
Copy pathspeed.rb
More file actions
78 lines (61 loc) · 1.65 KB
/
Copy pathspeed.rb
File metadata and controls
78 lines (61 loc) · 1.65 KB
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
77
78
require 'erb'
$LOAD_PATH.unshift File.dirname(__FILE__)
require 'helper'
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../test/fixtures'
require 'complex_view'
## erb
unless ENV['NOERB']
template = File.read(File.dirname(__FILE__) + '/complex.erb')
erb = ERB.new(template)
erb_scope = ComplexView.new
erb_scope.instance_eval("def render_erb; #{erb.src}; end")
bench 'ERB w/ caching' do
erb_scope.render_erb
end
unless ENV['CACHED']
erb_nocache_scope = ComplexView.new.send(:binding)
bench 'ERB w/o caching' do
ERB.new(template).result(erb_nocache_scope)
end
end
end
## haml
unless ENV['NOHAML']
require 'haml'
template = File.read(File.dirname(__FILE__) + '/complex.haml')
haml = Haml::Engine.new(template, :ugly => true)
haml_scope = ComplexView.new
haml.def_method(haml_scope, :render_haml)
bench 'HAML w/ caching' do
haml_scope.render_haml
end
unless ENV['CACHED']
haml_nocache_scope = ComplexView.new.send(:binding)
bench 'HAML w/o caching' do
Haml::Engine.new(template).render(haml_nocache_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