<commit_before>require "logger"

class Logger
  class Benchmarker
    attr :msg, true
    
    def initialize(msg)
      @msg, @start = msg, Time.now
    end
    
    def runtime
      Time.now - @start
    end
  end
  
  def benchmark(msg = "Benchmark", opts = {}, &block)
    benchmarker = Benchmarker.new(msg)
    r = yield(benchmarker)
    
    runtime = benchmarker.runtime
    warn "#{benchmarker.msg}: #{(runtime * 1000).to_i} msecs" if runtime > (opts[:minimum] || -1)
    r
  end
end<commit_msg>Benchmarker: adds :severity option<commit_after>require "logger"

class Logger
  class Benchmarker
    attr :msg, true
    attr :severity, true
    
    def initialize(msg, severity = :warn)
      @msg, @start = msg, Time.now
      @severity = severity
    end
    
    def runtime
      Time.now - @start
    end
  end
  
  def benchmark(msg = "Benchmark", opts = {}, &block)
    benchmarker = Benchmarker.new(msg, opts[:severity] || :warn)
    r = yield(benchmarker)
    
    runtime = benchmarker.runtime
    if runtime > (opts[:minimum] || -1)
      self.send benchmarker.severity, "#{benchmarker.msg}: #{(runtime * 1000).to_i} msecs" 
    end
    r
  rescue
    warn "FAIL #{benchmarker.msg}: #{(runtime * 1000).to_i} msecs" 
    raise
  end
end
{'fraction_non_alphanumeric': 0.12360446570972887, 'fraction_numerical': 0.011164274322169059, 'mean_word_length': 2.61671469740634, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3418799', 'n_tokens_mistral': 447, 'n_tokens_neox': 418, 'n_words': 111}