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,000 item array"
array = []
1.upto(1_000_000) {|i| array << i}
Benchmark.bmbm do |x|
x.report("string form") {
100.times do
logger.debug "a message with #{array.inspect}"
end
}
x.report("block form") {
100.times do
logger.debug { "a message with #{array.inspect}" }
end
}
end
# Inspecting 1,000,000 item array
# Rehearsal -----------------------------------------------
# string form 94.360000 1.990000 96.350000 ( 97.137403)
# block form 0.000000 0.000000 0.000000 ( 0.000299)
# ------------------------------------- total: 96.350000sec
#
# user system total real
# string form 94.370000 2.080000 96.450000 ( 97.750037)
# block form 0.000000 0.000000 0.000000 ( 0.000245)
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.