Sha256: 124edf6cfa151329507d51365d68e57b1c900926936f0dfc375869db1879f363

Contents?: true

Size: 1.15 KB

Versions: 71

Compression:

Stored size: 1.15 KB

Contents

# Run with
#
#   $ ruby -Ilib benchmarking/logging.rb
#

begin
  require "bench"
rescue LoadError
  $stderr.puts "`gem install bench` and try again."
  exit 1
end

require "redis"
require "logger"

def log(level, namespace = nil)
  logger = (namespace || Kernel).const_get(:Logger).new("/dev/null")
  logger.level = (namespace || Logger).const_get(level)
  logger
end

def stress(redis)
  redis.flushdb

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

  n.times do |i|
    key = "foo:#{i}"
    redis.set key, i
    redis.get key
  end
end

default = Redis.new

logging_redises = [
  Redis.new(:logger => log(:DEBUG)),
  Redis.new(:logger => log(:INFO)),
]

begin
  require "log4r"

  logging_redises += [
    Redis.new(:logger => log(:DEBUG, Log4r)),
    Redis.new(:logger => log(:INFO, Log4r)),
  ]
rescue LoadError
  $stderr.puts "Log4r not installed. `gem install log4r` if you want to compare it against Ruby's Logger (spoiler: it's much faster)."
end

benchmark "Default options (no logger)" do
  stress(default)
end

logging_redises.each do |redis|
  benchmark "#{redis.client.logger.class} on #{Logger::SEV_LABEL[redis.client.logger.level]}" do
    stress(redis)
  end
end

run 10

Version data entries

71 entries across 71 versions & 10 rubygems

Version Path
abaci-0.3.0 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
classiccms-0.7.5 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
classiccms-0.7.4 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
classiccms-0.7.3 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
classiccms-0.7.2 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
classiccms-0.7.1 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
classiccms-0.7.0 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
remq-0.0.4 vendor/bundle/gems/redis-3.0.2/benchmarking/logging.rb
remq-0.0.3 vendor/bundle/gems/redis-3.0.2/benchmarking/logging.rb
classiccms-0.6.9 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
classiccms-0.6.8 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
classiccms-0.6.7 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
classiccms-0.6.6 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
classiccms-0.6.5 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
classiccms-0.6.4 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
classiccms-0.6.3 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
classiccms-0.6.2 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
classiccms-0.6.1 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb
redis-3.0.2 benchmarking/logging.rb
classiccms-0.6.0 vendor/bundle/gems/redis-2.2.2/benchmarking/logging.rb