From ef78e2667d960bbbc9d6738eb9720d3748056980 Mon Sep 17 00:00:00 2001 From: nex3 Date: Fri, 23 Nov 2007 18:54:58 +0000 Subject: [PATCH] More benchmarky fun git-svn-id: svn://hamptoncatlin.com/haml/trunk@654 7063305b-7217-0410-af8c-cdc13e5119b9 --- Rakefile | 3 +-- test/benchmark.rb | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index d0ed0368..9d5456a0 100644 --- a/Rakefile +++ b/Rakefile @@ -22,8 +22,7 @@ desc temp_desc.chomp task :benchmark do require 'test/benchmark' - puts '-'*51, "Benchmark: Haml vs. Other Template Engines", '-'*51 - puts "Running benchmark #{ENV['TIMES']} times..." if ENV['TIMES'] + puts "Running benchmarks #{ENV['TIMES']} times..." if ENV['TIMES'] times = ENV['TIMES'].to_i if ENV['TIMES'] Haml.benchmark(times || 100) puts '-'*51 diff --git a/test/benchmark.rb b/test/benchmark.rb index 71bb4988..dd860e28 100644 --- a/test/benchmark.rb +++ b/test/benchmark.rb @@ -24,6 +24,8 @@ module Haml erb_template = File.read("#{directory}/rhtml/#{template_name}.rhtml") markaby_template = File.read("#{directory}/markaby/#{template_name}.mab") + puts '-'*51, "Haml and Friends: No Caching", '-'*51 + times = Benchmark.bmbm do |b| b.report("haml:") { runs.times { Haml::Engine.new(haml_template).render } } b.report("erb:") { runs.times { ERB.new(erb_template, nil, '-').render } } @@ -41,8 +43,42 @@ module Haml print_result["ERB", 1] print_result["Erubis", 2] print_result["Markaby", 3] + + puts '', '-' * 50, 'Haml and Friends: Cached', '-' * 50 + + haml = Haml::Engine.new(haml_template).render_proc + erb = ERB.new(erb_template, nil, '-') + erubis = Object.new + Erubis::Eruby.new(erb_template).def_method(erubis, :render) + mab = Markaby::Template.new(markaby_template) + times = Benchmark.bmbm do |b| + b.report("haml:") { runs.times { haml.call } } + b.report("erb:") { runs.times { erb.render } } + b.report("erubis:") { runs.times { erubis.render } } + b.report("mab:") { runs.times { mab.render } } + end + + print_result["ERB", 1] + print_result["Erubis", 2] + print_result["Markaby", 3] + + puts '', '-' * 50, 'Haml and Friends: Via ActionView', '-' * 50 + + require 'active_support' + require 'action_controller' + require 'action_view' + require 'haml/template' + + ActionView::Base.register_template_handler("haml", Haml::Template) + @base = ActionView::Base.new(File.dirname(__FILE__)) + times = Benchmark.bmbm do |b| + b.report("haml:") { runs.times { @base.render 'haml/templates/standard' } } + b.report("erb:") { runs.times { @base.render 'haml/rhtml/standard' } } + end + + print_result["ERB", 1] - puts '', '-' * 50, 'Sass on its own', '-' * 50 + puts '', '-' * 50, 'Sass', '-' * 50 sass_template = File.read("#{File.dirname(__FILE__)}/sass/templates/complex.sass") Benchmark.bmbm do |b|