Created
February 23, 2012 20:16
-
-
Save pglombardo/1894853 to your computer and use it in GitHub Desktop.
Block versus String With Incrementing Var Showdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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