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:
parent
62f4e6021c
commit
eb13419f3b
3 changed files with 36 additions and 17 deletions
7
Rakefile
7
Rakefile
|
@ -141,20 +141,23 @@ unless ARGV[0] == 'benchmark'
|
||||||
|
|
||||||
temp_desc = <<-END
|
temp_desc = <<-END
|
||||||
Run a profile of haml.
|
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.
|
TIMES=n sets the number of runs. Defaults to 100.
|
||||||
FILE=n sets the file to profile. Defaults to 'standard'.
|
FILE=n sets the file to profile. Defaults to 'standard'.
|
||||||
END
|
END
|
||||||
desc temp_desc.chomp
|
desc temp_desc.chomp
|
||||||
task :profile do
|
task :profile do
|
||||||
require 'test/profile'
|
require 'test/profile'
|
||||||
|
|
||||||
|
engine = ENV['ENGINE'] && ENV['ENGINE'].downcase == 'sass' ? Sass : Haml
|
||||||
|
|
||||||
puts '-'*51, "Profiling Haml::Template", '-'*51
|
puts '-'*51, "Profiling #{engine}", '-'*51
|
||||||
|
|
||||||
args = []
|
args = []
|
||||||
args.push ENV['TIMES'].to_i if ENV['TIMES']
|
args.push ENV['TIMES'].to_i if ENV['TIMES']
|
||||||
args.push ENV['FILE'] if ENV['FILE']
|
args.push ENV['FILE'] if ENV['FILE']
|
||||||
|
|
||||||
profiler = Haml::Profiler.new
|
profiler = engine::Profiler.new
|
||||||
res = profiler.profile(*args)
|
res = profiler.profile(*args)
|
||||||
puts res
|
puts res
|
||||||
|
|
||||||
|
|
1
TODO
1
TODO
|
@ -1,5 +1,4 @@
|
||||||
Testing:
|
Testing:
|
||||||
Test Sass for alternate options settings
|
|
||||||
Add Sass support for various utilities (benchmark, profile)
|
Add Sass support for various utilities (benchmark, profile)
|
||||||
|
|
||||||
Documentation:
|
Documentation:
|
||||||
|
|
|
@ -7,7 +7,26 @@ require 'profiler'
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
|
|
||||||
module Haml
|
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.
|
# the Ruby profiler for profiling haml code.
|
||||||
class Profiler
|
class Profiler
|
||||||
|
|
||||||
|
@ -28,19 +47,17 @@ module Haml
|
||||||
#
|
#
|
||||||
# Returns the results of the profiling as a string.
|
# Returns the results of the profiling as a string.
|
||||||
def profile(runs = 100, template_name = 'standard')
|
def profile(runs = 100, template_name = 'standard')
|
||||||
# Runs the profiler, collects information
|
AbstractProfiler.profile(runs) { @base.render template_name }
|
||||||
Profiler__::start_profile
|
end
|
||||||
runs.times { @base.render template_name }
|
end
|
||||||
Profiler__::stop_profile
|
end
|
||||||
|
|
||||||
# Outputs information to a StringIO, returns result
|
module Sass
|
||||||
io = StringIO.new
|
class Profiler
|
||||||
Profiler__::print_profile(io)
|
def profile(runs = 100, template_name = 'complex')
|
||||||
io.pos = 0
|
Haml::AbstractProfiler.profile(runs) do
|
||||||
result = io.read
|
Sass::Engine.new("#{File.dirname(__FILE__)}/sass/templates/#{template_name}.sass").render
|
||||||
io.close
|
end
|
||||||
return result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue