<commit_before>#!/usr/bin/env ruby

$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'), File.dirname(__FILE__))

require_relative './context'
require 'benchmark/ips'

require 'erb'
require 'erubis'
require 'fast_haml'
require 'haml'
require 'slim'
require 'tenjin'
require 'tilt'

class Benchmarks
  def initialize(time)
    @time    = time
    @benches = []

    @erb_code    = File.read(File.dirname(__FILE__) + '/view.erb')
    @haml_code   = File.read(File.dirname(__FILE__) + '/view.haml')
    @slim_code   = File.read(File.dirname(__FILE__) + '/view.slim')
    @rbhtml_path = File.dirname(__FILE__) + '/view.rbhtml'

    init_compiled_benches
  end

  def init_compiled_benches
    erb         = ERB.new(@erb_code)
    erubis      = Erubis::Eruby.new(@erb_code)
    fast_erubis = Erubis::FastEruby.new(@erb_code)
    haml_ugly   = Haml::Engine.new(@haml_code, format: :html5, ugly: true)
    tenjin      = Tenjin::Engine.new.get_template(@rbhtml_path)

    context = Context.new

    haml_ugly.def_method(context, :run_haml_ugly)
    context.instance_eval %{
      def run_erb; #{erb.src}; end
      def run_erubis; #{erubis.src}; end
      def run_temple_erb; #{Temple::ERB::Engine.new.call @erb_code}; end
      def run_fast_erubis; #{fast_erubis.src}; end
      def run_slim_ugly; #{Slim::Engine.new.call @slim_code}; end
      def run_fast_haml; #{FastHaml::Engine.new.call @haml_code}; end
      def run_tenjin; _buf = ''; #{tenjin.script}; end
    }

    bench('erubis')      { context.run_erubis }
    bench('tenjin')      { context.run_tenjin }
    bench('fast erubis') { context.run_fast_erubis }
    bench('fast_haml')   { context.run_fast_haml }
    bench('slim')        { context.run_slim_ugly }
    bench('temple erb')  { context.run_temple_erb }
    bench('erb')         { context.run_erb }
    bench('haml')        { context.run_haml_ugly }
  end<commit_msg>I'm pleased to add hamlit into template engines<commit_after>#!/usr/bin/env ruby

$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'), File.dirname(__FILE__))

require_relative './context'
require 'benchmark/ips'

require 'erb'
require 'erubis'
require 'fast_haml'
require 'haml'
require 'slim'
require 'tenjin'
require 'tilt'
require 'hamlit'

class Benchmarks
  def initialize(time)
    @time    = time
    @benches = []

    @erb_code    = File.read(File.dirname(__FILE__) + '/view.erb')
    @haml_code   = File.read(File.dirname(__FILE__) + '/view.haml')
    @slim_code   = File.read(File.dirname(__FILE__) + '/view.slim')
    @rbhtml_path = File.dirname(__FILE__) + '/view.rbhtml'

    init_compiled_benches
  end

  def init_compiled_benches
    erb         = ERB.new(@erb_code)
    erubis      = Erubis::Eruby.new(@erb_code)
    fast_erubis = Erubis::FastEruby.new(@erb_code)
    haml_ugly   = Haml::Engine.new(@haml_code, format: :html5, ugly: true)
    tenjin      = Tenjin::Engine.new.get_template(@rbhtml_path)

    context = Context.new

    haml_ugly.def_method(context, :run_haml_ugly)
    context.instance_eval %{
      def run_erb; #{erb.src}; end
      def run_erubis; #{erubis.src}; end
      def run_temple_erb; #{Temple::ERB::Engine.new.call @erb_code}; end
      def run_fast_erubis; #{fast_erubis.src}; end
      def run_slim_ugly; #{Slim::Engine.new.call @slim_code}; end
      def run_fast_haml; #{FastHaml::Engine.new.call @haml_code}; end
      def run_tenjin; _buf = ''; #{tenjin.script}; end
      def run_hamlit; #{Hamlit::Engine.new.call @haml_code}; end
    }

    bench('erubis')      { context.run_erubis }
    bench('slim')        { context.run_slim_ugly }
    bench('fast_haml')   { context.run_fast_haml }
    bench('tenjin')      { context.run_tenjin }
    bench('fast erubis') { context.run_fast_erubis }
    bench('temple erb')  { context.run_temple_erb }
    bench('erb')         { context.run_erb }
    bench('hamlit')      { context.run_hamlit }
    bench('haml')        { context.run_haml_ugly }
  end
{'fraction_non_alphanumeric': 0.1448170731707317, 'fraction_numerical': 0.0005081300813008131, 'mean_word_length': 3.408734602463606, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5795430', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1487, 'n_words': 247}