<commit_before><commit_msg>Benchmark objectless-feed.<commit_after>require 'chronologic'
require 'benchmark'

n_events = 100
# n_objects = rand(10)
n_objects = 20
n_feeds = 1000

Chronologic.connection = Cassandra.new('Chronologic')
protocol = Chronologic::Service::Protocol

timestamp = Time.now.tv_sec
timeline = ['objectless', timestamp].join('-')
puts "Benchmarking for #{timeline}"
puts Benchmark.measure {
  n_events.times do |i|
    objects = n_objects.times.map do |n|
      key = ['object', timestamp, n].join('-')
      data = {'value' => 'b' * 512}
      protocol.record(key, data)
      key
    end

    event = Chronologic::Event.new(
      :key => ['objectless', timestamp, i].join('-'),
      :data => {'foo' => 'a' * 768},
      :objects => {'things' => objects},
      :timelines => [timeline]
    )
    protocol.publish(event)
  end
}

Benchmark.bmbm(20) do |x|

  x.report("feed") do
    n_feeds.times { protocol.feed(timeline, :per_page => 20).items }
  end

  x.report("objectless") do
    n_feeds.times { protocol.feed(timeline, :per_page => 20, :strategy => "objectless").items }
  end

end

{'fraction_non_alphanumeric': 0.16606822262118492, 'fraction_numerical': 0.02064631956912029, 'mean_word_length': 3.6265560165975104, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6316511', 'n_tokens_mistral': 420, 'n_tokens_neox': 388, 'n_words': 84}