Last active
July 5, 2016 11:26
-
-
Save jkraemer/8f7c0ac282e504e467aff389d6ce145c to your computer and use it in GitHub Desktop.
logging and string interpolation
This file contains 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' | |
iterations = 1000000 | |
logger = Logger.new(STDOUT) | |
logger.level = Logger::ERROR | |
bar = 'bar' | |
foo = 'foo' | |
def method | |
'method' | |
end | |
Benchmark.bmbm(20) do |bm| | |
bm.report('{ "foo #{bar}" }') do | |
iterations.times do | |
logger.debug { "foo #{bar}" } | |
end | |
end | |
bm.report('"#{method} bar"') do | |
iterations.times do | |
logger.debug "#{method} bar" | |
end | |
end | |
bm.report('"#{foo} #{bar}"') do | |
iterations.times do | |
logger.debug "#{foo} #{bar}" | |
end | |
end | |
bm.report('"foo #{bar}"') do | |
iterations.times do | |
logger.debug "foo #{bar}" | |
end | |
end | |
bm.report('"foo bar"') do | |
iterations.times do | |
logger.debug "foo bar" | |
end | |
end | |
end |
This file contains 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
user system total real | |
{ "foo #{bar}" } 0.430000 0.000000 0.430000 ( 0.423957) | |
"#{method} bar" 0.400000 0.000000 0.400000 ( 0.399179) | |
"#{foo} #{bar}" 0.380000 0.000000 0.380000 ( 0.377865) | |
"foo #{bar}" 0.300000 0.000000 0.300000 ( 0.304749) | |
"foo bar" 0.220000 0.000000 0.220000 ( 0.214499) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment