Sha256: 6fff8fb6c895579c176ab97a75580c019310fae1d3fda19d54e6535b3fa96571

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

#!/usr/bin/env ruby
require 'benchmark/ips'
require 'haml'
require 'faml'
require 'hamlit'
require 'slim'
require 'escape_utils/html/haml'

unless ARGV[0]
  $stderr.puts "Usage: #{$0} template.haml [template.slim]"
  exit 1
end

haml_code = File.read(ARGV[0])
slim_code = ARGV[1] ? File.read(ARGV[1]) : nil

Benchmark.ips do |x|
  obj = Object.new

  Haml::Engine.new(haml_code, ugly: true, escape_html: true).def_method(obj, :haml)
  obj.instance_eval %{
    def faml_array; #{Faml::Engine.new.call(haml_code)}; end
    def faml_string; #{Faml::Engine.new(generator: Temple::Generators::RailsOutputBuffer).call(haml_code)}; end
    def hamlit_array; #{Hamlit::Engine.new(escape_html: true).call(haml_code)}; end
    def hamlit_string; #{Hamlit::Engine.new(escape_html: true, generator: Temple::Generators::RailsOutputBuffer).call(haml_code)}; end
  }
  if slim_code
    obj.instance_eval %{
      def slim_array; #{Slim::Engine.new.call(slim_code)}; end
      def slim_string; #{Slim::Engine.new(generator: Temple::Generators::RailsOutputBuffer).call(slim_code)}; end
    }
  end

  x.report('Haml') { obj.haml }
  x.report('Faml (Array)') { obj.faml_array }
  x.report('Faml (String)') { obj.faml_string }
  x.report('Hamlit (Array)') { obj.hamlit_array }
  x.report('Hamlit (String)') { obj.hamlit_string }
  if slim_code
    x.report('Slim (Array)') { obj.slim_array }
    x.report('Slim (String)') { obj.slim_string }
  end
  x.compare!
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
faml-0.2.12 benchmark/rendering.rb
faml-0.2.11 benchmark/rendering.rb
faml-0.2.10 benchmark/rendering.rb