1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Profiling works for Sass.

git-svn-id: svn://hamptoncatlin.com/haml/trunk@281 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2007-01-07 06:29:12 +00:00
parent 62f4e6021c
commit eb13419f3b
3 changed files with 36 additions and 17 deletions

View file

@ -141,6 +141,7 @@ unless ARGV[0] == 'benchmark'
temp_desc = <<-END
Run a profile of haml.
ENGINE=str sets the engine to be profiled (Haml or Sass).
TIMES=n sets the number of runs. Defaults to 100.
FILE=n sets the file to profile. Defaults to 'standard'.
END
@ -148,13 +149,15 @@ unless ARGV[0] == 'benchmark'
task :profile do
require 'test/profile'
puts '-'*51, "Profiling Haml::Template", '-'*51
engine = ENV['ENGINE'] && ENV['ENGINE'].downcase == 'sass' ? Sass : Haml
puts '-'*51, "Profiling #{engine}", '-'*51
args = []
args.push ENV['TIMES'].to_i if ENV['TIMES']
args.push ENV['FILE'] if ENV['FILE']
profiler = Haml::Profiler.new
profiler = engine::Profiler.new
res = profiler.profile(*args)
puts res

1
TODO
View file

@ -1,5 +1,4 @@
Testing:
Test Sass for alternate options settings
Add Sass support for various utilities (benchmark, profile)
Documentation:

View file

@ -7,7 +7,26 @@ require 'profiler'
require 'stringio'
module Haml
# A profiler for haml, mostly for development use. This simply implements
# Used by both Haml::Profiler and Sass::Profiler.
# Encapsulates profiling behavior.
module AbstractProfiler
def self.profile(times, &block)
# Runs the profiler, collects information
Profiler__::start_profile
times.times &block
Profiler__::stop_profile
# Outputs information to a StringIO, returns result
io = StringIO.new
Profiler__::print_profile(io)
io.pos = 0
result = io.read
io.close
result
end
end
# A profiler for Haml, mostly for development use. This simply implements
# the Ruby profiler for profiling haml code.
class Profiler
@ -28,19 +47,17 @@ module Haml
#
# Returns the results of the profiling as a string.
def profile(runs = 100, template_name = 'standard')
# Runs the profiler, collects information
Profiler__::start_profile
runs.times { @base.render template_name }
Profiler__::stop_profile
# Outputs information to a StringIO, returns result
io = StringIO.new
Profiler__::print_profile(io)
io.pos = 0
result = io.read
io.close
return result
AbstractProfiler.profile(runs) { @base.render template_name }
end
end
end
module Sass
class Profiler
def profile(runs = 100, template_name = 'complex')
Haml::AbstractProfiler.profile(runs) do
Sass::Engine.new("#{File.dirname(__FILE__)}/sass/templates/#{template_name}.sass").render
end
end
end
end