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 "Inspecting 1,000 item array"
array = []
1.upto(1_000) {|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
# Inspecting 1,000 item array
# Rehearsal -----------------------------------------------
# string form 65.790000 0.260000 66.050000 ( 68.107083)
# block form 0.330000 0.000000 0.330000 ( 0.338018)
# ------------------------------------- total: 66.380000sec
#
# user system total real
# string form 65.480000 0.250000 65.730000 ( 68.099213)
# block form 0.330000 0.000000 0.330000 ( 0.350882)
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.