diff --git a/Gemfile b/Gemfile index 9380cff8..d8ef2eca 100644 --- a/Gemfile +++ b/Gemfile @@ -3,4 +3,5 @@ source 'https://rubygems.org' # Specify your gem's dependencies in hamlit.gemspec gemspec +gem 'lineprof' gem 'pry' diff --git a/benchmark/compile.rake b/benchmark/compile.rake index e7b45b58..1559cdd8 100644 --- a/benchmark/compile.rake +++ b/benchmark/compile.rake @@ -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) diff --git a/benchmark/profile.rake b/benchmark/profile.rake new file mode 100644 index 00000000..ad6a5562 --- /dev/null +++ b/benchmark/profile.rake @@ -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