<commit_before>stage = Stage.new
format = "  %-25s %7d executions in %2.4f seconds"

skip_header = ARGV[1] == 'skip_header'

puts <<-DOC unless skip_header
Benchmarked Code
----------------
  proc = proc{}
  conproc = concurrent_proc{}
  
  while elapsed_seconds < 1
    # CODE #
  end
DOC

result_header = "Results for #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION}"
puts <<-DOC

#{result_header}
#{'-'*result_header.length}
  # CODE #
DOC

proc = proc{}
conproc = concurrent_proc{}

result = stage.measure(seconds: 1) do
  proc.call
end
puts sprintf(format, "proc.call:", result[:iterations], result[:time])

result = stage.measure(seconds: 1) do
  conproc.call
end
puts sprintf(format, "conproc.call:", result[:iterations], result[:time])

result = stage.measure(seconds: 1) do
  conproc.call_nonblock
end
puts sprintf(format, "conproc.call_nonblock:", result[:iterations], result[:time])

result = stage.measure(seconds: 1) do
  conproc.call_detached
end
puts sprintf(format, "conproc.call_detached:", result[:iterations], result[:time])

result = stage.measure(seconds: 1) do
  conproc.call_and_forget
end
puts sprintf(format, "conproc.call_and_forget:", result[:iterations], result[:time])<commit_msg>improved benchmark of various ways to call a concurrent proc<commit_after>stage = Stage.new
format = "  %-25s %7d executions in %2.4f seconds"

skip_header = ARGV[1] == 'skip_header'

puts <<-DOC unless skip_header
Benchmarked Code
----------------
  proc = proc{}
  conproc = concurrent_proc{}
  
  while elapsed_seconds < 1
    #CALL#
  end
DOC

result_header = "Results for #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION}"
puts <<-DOC

#{result_header}
#{'-'*result_header.length}
  #CALL#
DOC

proc = proc{}
conproc = concurrent_proc{}

result = stage.measure(seconds: 1) do
  proc.call
end
puts sprintf(format, "proc.call:", result[:iterations], result[:time])

result = stage.measure(seconds: 1) do
  conproc.call
end
puts sprintf(format, "conproc.call:", result[:iterations], result[:time])

result = stage.measure(seconds: 1) do
  conproc.call_nonblock
end
puts sprintf(format, "conproc.call_nonblock:", result[:iterations], result[:time])

result = stage.measure(seconds: 1) do
  conproc.call_detached
end
puts sprintf(format, "conproc.call_detached:", result[:iterations], result[:time])

result = stage.measure(seconds: 1) do
  conproc.call_and_forget
end
puts sprintf(format, "conproc.call_and_forget:", result[:iterations], result[:time])
{'fraction_non_alphanumeric': 0.15088150881508816, 'fraction_numerical': 0.00984009840098401, 'mean_word_length': 5.192893401015229, 'pattern_counts': {'":': 0, '<': 13, '<?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': '736076', 'n_tokens_mistral': 876, 'n_tokens_neox': 842, 'n_words': 204}