<commit_before>#!/usr/bin/env ruby

$:.push File.expand_path("../../lib", __FILE__)

require 'benchmark'
require 'celluloid'

class RegularObject
  def example; end
end

class ConcurrentObject
  include Celluloid::Actor
  def example; end
end

def measure(reps = 1000, &block)
  time = Benchmark.measure do
    reps.times(&block)
  end.real
  
  1 / time * reps
end

def format(float)
  "%0.2f" % float
end

#
# OBJECT CREATION
#

puts "objects_per_second:"

sequential_creation = measure(100000) { RegularObject.new }
concurrent_creation = measure         { ConcurrentObject.new }

puts "  sequential: #{format sequential_creation}"
puts "  concurrent: #{format concurrent_creation}"

puts "  delta: #{format sequential_creation / concurrent_creation }"

#
# METHOD CALLS
#

puts "method_calls_per_second:"

sequential_object = RegularObject.new
sequential_calls = measure(100000) { sequential_object.example }

concurrent_object = ConcurrentObject.new
concurrent_calls = measure { concurrent_object.example }

puts "  sequential: #{format sequential_calls}"<commit_msg>Increase number of repetitions in call benchmarks<commit_after>#!/usr/bin/env ruby

$:.push File.expand_path("../../lib", __FILE__)

require 'benchmark'
require 'celluloid'

class RegularObject
  def example; end
end

class ConcurrentObject
  include Celluloid::Actor
  def example; end
end

def measure(reps, &block)
  time = Benchmark.measure do
    reps.times(&block)
  end.real
  
  1 / time * reps
end

def format(float)
  "%0.2f" % float
end

#
# OBJECT CREATION
#

puts "objects_per_second:"

sequential_creation = measure(100000) { RegularObject.new }
concurrent_creation = measure(1000)   { ConcurrentObject.new }

puts "  sequential: #{format sequential_creation}"
puts "  concurrent: #{format concurrent_creation}"

puts "  delta: #{format sequential_creation / concurrent_creation }"

#
# METHOD CALLS
#

puts "method_calls_per_second:"

sequential_object = RegularObject.new
sequential_calls = measure(10000000) { sequential_object.example }

concurrent_object = ConcurrentObject.new
concurrent_calls = measure(20000)   { concurrent_object.example }

puts "  sequential: #{format sequential_calls}"
{'fraction_non_alphanumeric': 0.10494958753437214, 'fraction_numerical': 0.020623281393217233, 'mean_word_length': 4.915989159891599, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '6398149', 'n_tokens_mistral': 769, 'n_tokens_neox': 700, 'n_words': 168}