Profile compilation
This commit is contained in:
parent
292ed64ced
commit
74ef63f2a4
1
Gemfile
1
Gemfile
|
@ -3,4 +3,5 @@ source 'https://rubygems.org'
|
||||||
# Specify your gem's dependencies in hamlit.gemspec
|
# Specify your gem's dependencies in hamlit.gemspec
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
|
gem 'lineprof'
|
||||||
gem 'pry'
|
gem 'pry'
|
||||||
|
|
|
@ -55,6 +55,9 @@ namespace :benchmark do
|
||||||
json_path = File.expand_path('../test/haml-spec/tests.json', __dir__)
|
json_path = File.expand_path('../test/haml-spec/tests.json', __dir__)
|
||||||
contexts = JSON.parse(File.read(json_path))
|
contexts = JSON.parse(File.read(json_path))
|
||||||
|
|
||||||
|
faml_engine = Faml::Engine.new(filename: '')
|
||||||
|
hamlit_engine = Hamlit::Engine.new
|
||||||
|
|
||||||
contexts.each do |context|
|
contexts.each do |context|
|
||||||
context[1].each do |name, test|
|
context[1].each do |name, test|
|
||||||
haml = test['haml']
|
haml = test['haml']
|
||||||
|
@ -65,8 +68,8 @@ namespace :benchmark do
|
||||||
|
|
||||||
begin
|
begin
|
||||||
haml_time = Benchmark.bench { Haml::Engine.new(haml, options).precompiled }
|
haml_time = Benchmark.bench { Haml::Engine.new(haml, options).precompiled }
|
||||||
faml_time = Benchmark.bench { Faml::Engine.new(filename: '').call(haml) }
|
faml_time = Benchmark.bench { faml_engine.call(haml) }
|
||||||
hamlit_time = Benchmark.bench { Hamlit::HamlEngine.new(haml, options).precompiled }
|
hamlit_time = Benchmark.bench { hamlit_engine.call(haml) }
|
||||||
|
|
||||||
haml_benchmark.capture(haml_time)
|
haml_benchmark.capture(haml_time)
|
||||||
faml_benchmark.capture(faml_time)
|
faml_benchmark.capture(faml_time)
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue