<commit_before>require 'benchmark'
require "#{File.dirname(__FILE__)}/../lib/lawnchair"

Lawnchair.redis.flushdb

# *** Performing 1000 iterations ***
#              user       system        total        real
# cached:     0.140000    0.040000    0.180000    ( 0.292324)
# not cached: 26.070000   0.620000    26.690000   ( 27.156388)

n = (ARGV.shift || 1000).to_i

puts "*** Performing #{n} iterations ***"

def expensive_stuff
  100.times do
    Date.parse("Dec 3. 1981")
  end
end

Benchmark.bm(7) do |x|
  x.report("cached:") do
    (1..n).each do |i|
      Lawnchair::Cache.me(:key => "foo") do
        expensive_stuff
      end
    end
  end
  
  x.report("not cached:") do
    (1..n).each do |i|
      expensive_stuff
    end
  end
end
<commit_msg>modified speed test a bit<commit_after>require 'benchmark'
require "#{File.dirname(__FILE__)}/../lib/lawnchair"

Lawnchair.redis.flushdb

# *** Performing 1000 iterations ***
#              user       system        total        real
# cached:     0.140000    0.040000    0.180000    ( 0.292324)
# not cached: 26.070000   0.620000    26.690000   ( 27.156388)

n = (ARGV.shift || 1000).to_i

puts "*** Performing #{n} iterations ***"

def expensive_stuff
  a = []
  100.times do
    a << Date.parse("Dec 3. 1981")
  end
end

Benchmark.bm(7) do |x|
  x.report("cached:") do
    (1..n).each do |i|
      Lawnchair::Cache.me(:key => "foo") do
        expensive_stuff
      end
    end
  end
  
  x.report("not cached:") do
    (1..n).each do |i|
      expensive_stuff
    end
  end
end

{'fraction_non_alphanumeric': 0.146484375, 'fraction_numerical': 0.1015625, 'mean_word_length': 2.284188034188034, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7078263', 'n_tokens_mistral': 680, 'n_tokens_neox': 561, 'n_words': 134}