Sha256: a122c1052d89c257f5ec2bec0896d2c0411112f9b8b828f11e9d76667116746c

Contents?: true

Size: 1.52 KB

Versions: 18

Compression:

Stored size: 1.52 KB

Contents

require 'bundler/setup'
require 'madvertise-logging'
require 'benchmark'

puts "Using " + %x(ruby -v)
puts

$log = Madvertise::Logging::ImprovedLogger.new(:buffer)

STRING_A = ("a string"*10).freeze
STRING_B = ("b string"*10).freeze

n = 2000000

puts ">>> Testing String interpolation vs. concatenation (n=#{n})"

Benchmark.bmbm do |x|
  x.report("append double") { n.times do; "" << STRING_A << STRING_B << STRING_A; end }
  x.report("concat double") { n.times do; STRING_A + STRING_B + STRING_A; end }
  x.report("concat interp") { n.times do; "#{STRING_A}#{STRING_B}#{STRING_A}"; end }
end

n = 50000

puts
puts ">>> Testing caller"
Benchmark.bmbm do |x|
  x.report("caller") { n.times do; caller; end }
end

$debug = false
$log.level = :info

puts
puts ">>> Testing log.debug with debug disabled (n=#{n})"
Benchmark.bmbm do |x|
  x.report("debug w/  guard") { n.times do; $log.debug(STRING_A) if $debug; end }
  x.report("debug w/  block") { n.times do; $log.debug{STRING_A}; end }
  x.report("debug w/  block + concat") { n.times do; $log.debug{"#{STRING_A}#{STRING_B}#{STRING_A}"}; end }
  x.report("debug w/o guard") { n.times do; $log.debug(STRING_A); end }
  x.report("debug w/o guard + concat") { n.times do; $log.debug("#{STRING_A}#{STRING_B}#{STRING_A}"); end }
end

$debug = true
$log.level = :debug

puts
puts ">>> Testing log.debug with debug enabled (n=#{n})"
Benchmark.bmbm do |x|
  x.report("debug w/  guard") { n.times do; $log.debug(STRING_A) if $debug; end }
  x.report("debug w/o guard") { n.times do; $log.debug(STRING_A); end }
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
madvertise-logging-1.0.2 benchmark.rb
madvertise-logging-1.0.1 benchmark.rb
madvertise-logging-1.0.0 benchmark.rb
madvertise-logging-1.0.0.rc4 benchmark.rb
madvertise-logging-1.0.0.rc3 benchmark.rb
madvertise-logging-1.0.0.rc2 benchmark.rb
madvertise-logging-1.0.0.rc1 benchmark.rb
madvertise-logging-0.9.4 benchmark.rb
madvertise-logging-0.9.3 benchmark.rb
madvertise-logging-0.9.2 benchmark.rb
madvertise-logging-0.9.1 benchmark.rb
madvertise-logging-0.9.0 benchmark.rb
madvertise-logging-0.8.1 benchmark.rb
madvertise-logging-0.8.0 benchmark.rb
madvertise-logging-0.7.3 benchmark.rb
madvertise-logging-0.7.2 benchmark.rb
madvertise-logging-0.7.1 benchmark.rb
madvertise-logging-0.7.0 benchmark.rb