<commit_before>if ARGV.empty?
  $stderr.puts "Usage: ./script/performance/profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html]"
  exit(1)
end

# Keep the expensive require out of the profile.
$stderr.puts 'Loading Rails...'
require RAILS_ROOT + '/config/environment'

# Define a method to profile.
if ARGV[1] and ARGV[1].to_i > 1
  eval "def profile_me() #{ARGV[1]}.times { #{ARGV[0]} } end"
else
  eval "def profile_me() #{ARGV[0]} end"
end

# Use the ruby-prof extension if available.  Fall back to stdlib profiler.
begin
  begin
    require "ruby-prof"
    $stderr.puts 'Using the ruby-prof extension.'
    RubyProf.measure_mode = RubyProf::WALL_TIME
    RubyProf.start
    profile_me
    results = RubyProf.stop
    if ARGV[2]
      printer_class = RubyProf.const_get((ARGV[2] + "_printer").classify)
    else
      printer_class = RubyProf::FlatPrinter
    end
    printer = printer_class.new(results)
    printer.print($stderr, 0)<commit_msg>Supply valid ruby-prof parameters [#1804 state:resolved]<commit_after>if ARGV.empty?
  $stderr.puts "Usage: ./script/performance/profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html]"
  exit(1)
end

# Keep the expensive require out of the profile.
$stderr.puts 'Loading Rails...'
require RAILS_ROOT + '/config/environment'

# Define a method to profile.
if ARGV[1] and ARGV[1].to_i > 1
  eval "def profile_me() #{ARGV[1]}.times { #{ARGV[0]} } end"
else
  eval "def profile_me() #{ARGV[0]} end"
end

# Use the ruby-prof extension if available.  Fall back to stdlib profiler.
begin
  begin
    require "ruby-prof"
    $stderr.puts 'Using the ruby-prof extension.'
    RubyProf.measure_mode = RubyProf::WALL_TIME
    RubyProf.start
    profile_me
    results = RubyProf.stop
    if ARGV[2]
      printer_class = RubyProf.const_get((ARGV[2] + "_printer").classify)
    else
      printer_class = RubyProf::FlatPrinter
    end
    printer = printer_class.new(results)
    printer.print($stderr)
{'fraction_non_alphanumeric': 0.12474645030425964, 'fraction_numerical': 0.013691683569979716, 'mean_word_length': 3.883663366336634, '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': '2641775', 'n_tokens_mistral': 712, 'n_tokens_neox': 677, 'n_words': 175}