Created
November 28, 2013 20:08
-
-
Save kuldeepaggarwal/7697489 to your computer and use it in GitHub Desktop.
accessing constants and create string at run time
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 'benchmark/ips' | |
QUOTED_TRUE = "'t'" | |
def quoted_true | |
QUOTED_TRUE | |
end | |
def quoted_true_ | |
"'t'" | |
end | |
Benchmark.ips { |p| | |
p.report("old quoted_true") do | |
quoted_true_ | |
end | |
p.report("new quoted_true") do | |
quoted_true | |
end | |
}; | |
Calculating ------------------------------------- | |
old quoted_true 32325 i/100ms | |
new quoted_true 33601 i/100ms | |
------------------------------------------------- | |
old quoted_true 4758373.5 (±32.0%) i/s - 18005025 in 4.994071s | |
new quoted_true 7667214.5 (±4.0%) i/s - 38237938 in 4.997284s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment