Sha256: da9125a05fc74561541a93319f4efade4b4f4cd91dc91018ae36db19163be1e3
Contents?: true
Size: 1.02 KB
Versions: 7
Compression:
Stored size: 1.02 KB
Contents
# Runs a mild benchmark and prints out the average time a call to 'throttle!' takes. require 'prorate' require 'benchmark' require 'redis' require 'securerandom' def average_ms(ary) ary.map { |x| x * 1000 }.inject(0, &:+) / ary.length end r = Redis.new logz = Logger.new(STDERR) logz.level = Logger::FATAL # block out most stuff times = [] 50.times do times << Benchmark.realtime { t = Prorate::Throttle.new(redis: r, logger: logz, name: "throttle-login-email", limit: 60, period: 30, block_for: 5) # Add all the parameters that function as a discriminator t << '127.0.2.1' t << 'no_person@nowhere.com' t.throttle! } end puts average_ms times times = [] 50.times do email = SecureRandom.hex(20) ip = SecureRandom.hex(10) times << Benchmark.realtime { t = Prorate::Throttle.new(redis: r, logger: logz, name: "throttle-login-email", limit: 30, period: 30, block_for: 5) # Add all the parameters that function as a discriminator t << ip t << email t.throttle! } end puts average_ms times
Version data entries
7 entries across 7 versions & 1 rubygems