<commit_before>
require 'benchmark/ips'

require_relative '../lib/bade'
require_relative 'constants'


Benchmark.ips do |b|
  b.report('render always') { Bade::Renderer.from_file(TEMPLATE_PATH).with_locals(TEMPLATE_VARS).render(new_line: '') }

  precompiled = Bade::Renderer.from_file(TEMPLATE_PATH).precompiled
  b.report('prerendered') { Bade::Renderer.from_precompiled(precompiled, TEMPLATE_PATH).with_locals(TEMPLATE_VARS).render(new_line: '') }
end





text = 'abcdefghijklmnopqrstuvwxyz'.gsub(/./, "\t")

Benchmark.ips do |b|

  b.report('String#each_char with if') { |times|
    times.times {
      count = 0
      text.each_char do |char|
        if char == ' '
          count += 1
        elsif char == "\t"
          count += 4
        else
          break
        end
      end
    }
  }

  b.report('String#each_char with case') { |times|
    times.times {
      count = 0
      text.each_char do |char|
        case char
        when ' '
          count += 1
        when "\t"
          count += 4
        else
          break
        end
      end
    }
  }

  b.report('Manual with String#[] with if') { |times|
    times.times {
      count = 0
      text.length.times { |idx|
        if text[idx] == ' '
          count += 1
        elsif text[idx] == "\t"
          count += 4
        else
          break
        end
      }
    }
  }
end
<commit_msg>[Benchmarks] remove string code<commit_after>
require 'benchmark/ips'

require_relative '../lib/bade'
require_relative 'constants'


Benchmark.ips do |b|
  b.report('render always') { Bade::Renderer.from_file(TEMPLATE_PATH).with_locals(TEMPLATE_VARS).render(new_line: '') }

  precompiled = Bade::Renderer.from_file(TEMPLATE_PATH).precompiled
  b.report('prerendered') { Bade::Renderer.from_precompiled(precompiled, TEMPLATE_PATH).with_locals(TEMPLATE_VARS).render(new_line: '') }
end

{'fraction_non_alphanumeric': 0.13293864370290634, 'fraction_numerical': 0.004843918191603875, 'mean_word_length': 2.5075471698113208, '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': '2984804', 'n_tokens_mistral': 669, 'n_tokens_neox': 633, 'n_words': 117}