public
Rubygem
Description: HTML Abstraction Markup Language - A Markup Haiku
Homepage: http://haml.hamptoncatlin.com
Clone URL: git://github.com/nex3/haml.git
Search Repo:
Cleaning up the profile Rake task.
nex3 (author)
Thu May 15 15:43:32 -0700 2008
commit  b9d4015743b66f3db93eceec5bfc283919f1da8a
tree    20f8435c19c6d511362db9068d13610255dd8789
parent  c8f67659bbfad098d10b5b83d07fa34dc89762e9
...
109
110
111
112
 
 
 
 
113
114
115
116
 
 
 
 
 
 
117
118
119
 
 
 
 
120
121
 
 
122
123
 
 
 
 
124
125
126
127
 
 
 
 
 
128
129
130
131
132
133
134
 
 
 
...
109
110
111
 
112
113
114
115
116
 
 
 
117
118
119
120
121
122
123
 
 
124
125
126
127
128
 
129
130
131
 
132
133
134
135
136
 
 
 
137
138
139
140
141
142
 
 
 
 
 
 
143
144
145
0
@@ -109,27 +109,38 @@
0
 
0
 # ----- Profiling -----
0
 
0
-desc <<END
0
+begin
0
+ require 'ruby-prof'
0
+
0
+ desc <<END
0
 Run a profile of haml.
0
- ENGINE=str sets the engine to be profiled (Haml or Sass).
0
- TIMES=n sets the number of runs. Defaults to 100.
0
- FILE=n sets the file to profile. Defaults to 'standard'.
0
+ ENGINE=str sets the engine to be profiled. Defaults to Haml.
0
+ TIMES=n sets the number of runs. Defaults to 1000.
0
+ FILE=str sets the file to profile.
0
+ Defaults to 'standard' for Haml and 'complex' for Sass.
0
+ OUTPUT=str sets the ruby-prof output format.
0
+ Can be Flat, CallInfo, or Graph. Defaults to Flat. Defaults to Flat.
0
 END
0
-task :profile do
0
- require 'test/profile'
0
+ task :profile do
0
+ engine = (ENV['ENGINE'] || 'haml').downcase
0
+ times = (ENV['TIMES'] || '1000').to_i
0
+ file = ENV['FILE']
0
 
0
- engine = ENV['ENGINE'] && ENV['ENGINE'].downcase == 'sass' ? Sass : Haml
0
+ if engine == 'sass'
0
+ require 'lib/sass'
0
 
0
- puts '-'*51, "Profiling #{engine}", '-'*51
0
+ file = File.read("#{File.dirname(__FILE__)}/test/sass/templates/#{file || 'complex'}.sass")
0
+ result = RubyProf.profile { times.times { Sass::Engine.new(file).render } }
0
+ else
0
+ require 'lib/haml'
0
 
0
- args = []
0
- args.push ENV['TIMES'].to_i if ENV['TIMES']
0
- args.push ENV['FILE'] if ENV['FILE']
0
+ file = File.read("#{File.dirname(__FILE__)}/test/haml/templates/#{file || 'standard'}.haml")
0
+ obj = Object.new
0
+ Haml::Engine.new(file).def_method(obj, :render)
0
+ result = RubyProf.profile { times.times { obj.render } }
0
+ end
0
 
0
- profiler = engine::Profiler.new
0
- res = profiler.profile(*args)
0
- puts res
0
-
0
- puts '-'*51
0
-end
0
+ RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
0
+ end
0
+rescue LoadError; end
...
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
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,66 +1 @@
0
-require 'rubygems'
0
-require 'active_support'
0
-require 'action_controller'
0
-require 'action_view'
0
-
0
-require File.dirname(__FILE__) + '/../lib/haml'
0
-require 'haml/template'
0
-
0
-require 'profiler'
0
-require 'stringio'
0
-
0
-module Haml
0
- # Used by both Haml::Profiler and Sass::Profiler.
0
- # Encapsulates profiling behavior.
0
- module AbstractProfiler
0
- def self.profile(times, &block)
0
- # Runs the profiler, collects information
0
- Profiler__::start_profile
0
- times.times &block
0
- Profiler__::stop_profile
0
-
0
- # Outputs information to a StringIO, returns result
0
- io = StringIO.new
0
- Profiler__::print_profile(io)
0
- io.pos = 0
0
- result = io.read
0
- io.close
0
- result
0
- end
0
- end
0
-
0
- # A profiler for Haml, mostly for development use. This simply implements
0
- # the Ruby profiler for profiling haml code.
0
- class Profiler
0
-
0
- # Creates a new profiler that looks for templates in the base
0
- # directory.
0
- def initialize(base = File.join(File.dirname(__FILE__), 'haml', 'templates'))
0
- unless base.class == ActionView::Base
0
- @base = ActionView::Base.new(base)
0
- else
0
- @base = base
0
- end
0
- end
0
-
0
- # Profiles haml on the given template with the given number of runs.
0
- # The template name shouldn't have a file extension; this will
0
- # automatically look for a haml template.
0
- #
0
- # Returns the results of the profiling as a string.
0
- def profile(runs = 100, template_name = 'standard')
0
- AbstractProfiler.profile(runs) { @base.render template_name }
0
- end
0
- end
0
-end
0
-
0
-module Sass
0
- class Profiler
0
- def profile(runs = 100, template_name = 'complex')
0
- Haml::AbstractProfiler.profile(runs) do
0
- Sass::Engine.new("#{File.dirname(__FILE__)}/sass/templates/#{template_name}.sass").render
0
- end
0
- end
0
- end
0
-end

Comments

    No one has commented yet.