Skip to content

Instantly share code, notes, and snippets.

@pglombardo
Created February 23, 2012 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pglombardo/1894853 to your computer and use it in GitHub Desktop.
Save pglombardo/1894853 to your computer and use it in GitHub Desktop.
Block versus String With Incrementing Var Showdown
require 'benchmark'
require 'logger'
logger = Logger.new("/dev/null")
logger.level = Logger::INFO
puts "Simple Strings"
Benchmark.bmbm do |x|
x.report("string form") {
x = 0
100_000.times do
logger.debug "a simple string message with var #{x}"
x+=1
end
}
x.report("block form") {
x = 0
100_000.times do
logger.debug { "a simple string message with var #{x}" }
x+=1
end
}
end
puts
Simple Strings
Rehearsal -----------------------------------------------
string form 0.230000 0.000000 0.230000 ( 0.228999)
block form 0.350000 0.020000 0.370000 ( 0.373413)
-------------------------------------- total: 0.600000sec
user system total real
string form 0.250000 0.000000 0.250000 ( 0.250874)
block form 0.340000 0.020000 0.360000 ( 0.354017)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment