Profile compilation

This commit is contained in:
Takashi Kokubun 2015-10-11 18:31:58 +09:00
parent 292ed64ced
commit 74ef63f2a4
3 changed files with 37 additions and 2 deletions

View File

@ -3,4 +3,5 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in hamlit.gemspec
gemspec
gem 'lineprof'
gem 'pry'

View File

@ -55,6 +55,9 @@ namespace :benchmark do
json_path = File.expand_path('../test/haml-spec/tests.json', __dir__)
contexts = JSON.parse(File.read(json_path))
faml_engine = Faml::Engine.new(filename: '')
hamlit_engine = Hamlit::Engine.new
contexts.each do |context|
context[1].each do |name, test|
haml = test['haml']
@ -65,8 +68,8 @@ namespace :benchmark do
begin
haml_time = Benchmark.bench { Haml::Engine.new(haml, options).precompiled }
faml_time = Benchmark.bench { Faml::Engine.new(filename: '').call(haml) }
hamlit_time = Benchmark.bench { Hamlit::HamlEngine.new(haml, options).precompiled }
faml_time = Benchmark.bench { faml_engine.call(haml) }
hamlit_time = Benchmark.bench { hamlit_engine.call(haml) }
haml_benchmark.capture(haml_time)
faml_benchmark.capture(faml_time)

31
benchmark/profile.rake Normal file
View File

@ -0,0 +1,31 @@
$:.unshift File.expand_path('../lib', __FILE__)
require 'hamlit'
require 'json'
namespace :benchmark do
desc 'Profile compilation'
task :profile do
json_path = File.expand_path('../test/haml-spec/tests.json', __dir__)
contexts = JSON.parse(File.read(json_path))
hamlit_engine = Hamlit::Engine.new
Lineprof.profile(/hamlit|temple/) do
contexts.each do |context|
context[1].each do |name, test|
haml = test['haml']
locals = Hash[(test['locals'] || {}).map {|x, y| [x.to_sym, y]}]
options = Hash[(test['config'] || {}).map {|x, y| [x.to_sym, y]}]
options[:format] = options[:format].to_sym if options.key?(:format)
options = { ugly: true }.merge(options)
begin
hamlit_engine.call(haml)
rescue Temple::FilterError, TypeError
end
end
end
end
end
end