Skip to content

Instantly share code, notes, and snippets.

@voidlock voidlock/file.rb
Created Jul 11, 2009

Embed
What would you like to do?
require 'benchmark'
require 'logger'
logger = Logger.new("/dev/null")
logger.level = Logger::INFO
puts "Small string substition"
array = []
1.upto(10) {|i| array << i}
Benchmark.bmbm do |x|
x.report("string form") {
100_000.times do
logger.debug "a message with #{array.inspect}"
end
}
x.report("block form") {
100_000.times do
logger.debug { "a message with #{array.inspect}" }
end
}
end
puts
# Small string substition
# Rehearsal -----------------------------------------------
# string form 0.910000 0.000000 0.910000 ( 0.914628)
# block form 0.320000 0.000000 0.320000 ( 0.322889)
# -------------------------------------- total: 1.230000sec
#
# user system total real
# string form 0.900000 0.000000 0.900000 ( 0.911639)
# block form 0.330000 0.000000 0.330000 ( 0.329468)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.