<commit_before>gem "ruby-prof"
require "ruby-prof"
require "stringio"


module SpeedUp


  class ProfileTest

    def self.test_name
      self.name.split("::").last.match(/(?:PR_)?(.+)/)[1]
    end

    def self.tests
      public_instance_methods(true).grep(/^profile_/i).sort
    end

    def self.each_test_with_name(&block)
      self.tests.each { |method|
        name = method.to_s.match(/profile_(.+)/)[1]
        name.tr!("_", " ")
        yield(method, name)
      }
    end

    def self.run(profile_method)
      instance = self.new
      instance.send(:setup)
      SpeedUp.profile do
        instance.send(profile_method)
      end
      instance.send(:teardown)
    end

    def setup; end
    def teardown; end

  end # class


  class CallStackPrinter < RubyProf::CallStackPrinter

    def print_header
      @output.puts "<html><head>"
      @output.puts '<meta http-equiv="X-UA-Compatible" content="IE=edge"/>'
      @output.puts '<meta http-equiv="content-type" content="text/html; charset=utf-8">'
      @output.puts "<title>#{h title}</title>"
      print_css
      print_java_script
      @output.puts '</head><body><div style="display: inline-block;">'
      print_title_bar
      print_commands
      print_help
    end
<commit_msg>Adding benchmarking support for the profiling tests.<commit_after>gem "ruby-prof"
require "ruby-prof"

require "benchmark"
require "set"
require "stringio"


module SpeedUp


  class ProfileTest

    def self.test_name
      self.name.split("::").last.match(/(?:PR_)?(.+)/)[1]
    end

    def self.tests
      public_instance_methods(true).grep(/^profile_/i).sort
    end

    def self.each_test_with_name(&block)
      self.tests.each { |method|
        name = method.to_s.match(/profile_(.+)/)[1]
        name.tr!("_", " ")
        yield(method, name)
      }
    end

    def self.run(profile_method)
      instance = self.new
      instance.send(:setup)
      SpeedUp.profile do
        instance.send(profile_method)
      end
      instance.send(:teardown)
    end

    def self.benchmark
      instance = self.new
      label_size = tests.map { |t| t.to_s.size }.max
      Benchmark.bm(label_size) do |x|
        self.each_test_with_name { |method, name|
          instance.send(:setup)
          x.report(name)   { instance.send(method) }
          instance.send(:teardown)
        }
      end
    end

    def setup; end
    def teardown; end

  end # class


  class CallStackPrinter < RubyProf::CallStackPrinter

    def print_header
      @output.puts "<html><head>"
      @output.puts '<meta http-equiv="X-UA-Compatible" content="IE=edge"/>'
      @output.puts '<meta http-equiv="content-type" content="text/html; charset=utf-8">'
      @output.puts "<title>#{h title}</title>"
      print_css
      print_java_script
      @output.puts '</head><body><div style="display: inline-block;">'
      print_title_bar
      print_commands
      print_help
    end

{'fraction_non_alphanumeric': 0.1359754014349163, 'fraction_numerical': 0.0020498804236419544, 'mean_word_length': 2.5707317073170732, 'pattern_counts': {'":': 2, '<': 23, '<?xml version=': 0, '>': 21, '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': '4175985', 'n_tokens_mistral': 994, 'n_tokens_neox': 959, 'n_words': 183}