forked from haml/haml
-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark.rb
66 lines (52 loc) · 1.66 KB
/
benchmark.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
require "bundler/setup"
require "haml"
require "rbench"
times = (ARGV.first || 1000).to_i
if times == 0 # Invalid parameter
puts <<END
ruby #$0 [times=1000]
Benchmark Haml against various other templating languages.
END
exit 1
end
%w[erb erubi rails active_support action_controller
action_view action_pack haml/template rbench].each {|dep| require(dep)}
def view
base = ActionView::Base.new
base.view_paths << File.join(File.dirname(__FILE__), '/test')
base
end
def render(view, file)
view.render :file => file
end
RBench.run(times) do
column :haml, :title => "Haml"
column :erb, :title => "ERB"
column :erubi, :title => "Erubi"
template_name = 'standard'
haml_template = File.read("#{File.dirname(__FILE__)}/test/templates/#{template_name}.haml")
erb_template = File.read("#{File.dirname(__FILE__)}/test/erb/#{template_name}.erb")
report "Cached" do
obj = Object.new
Haml::Engine.new(haml_template).def_method(obj, :haml)
obj.instance_eval("def erb; #{ERB.new(erb_template, nil, '-').src}; end")
obj.instance_eval("def erubi; #{Erubi::Engine.new(erb_template).src}; end")
haml { obj.haml }
erb { obj.erb }
erubi { obj.erubi }
end
report "ActionView" do
# To cache the template
render view, 'templates/standard'
render view, 'erb/standard'
haml { render view, 'templates/standard' }
erubi { render view, 'erb/standard' }
end
report "ActionView with deep partials" do
# To cache the template
render view, 'templates/action_view'
render view, 'erb/action_view'
haml { render view, 'templates/action_view' }
erubi { render view, 'erb/action_view' }
end
end