Created
May 7, 2011 10:31
-
-
Save erubboli/960395 to your computer and use it in GitHub Desktop.
concatenation vs interpolation
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' | |
Benchmark.bm do |x| | |
x.report("concatenation") do | |
for i in 0..30000000 do | |
str = "a=" << "10" << ",b=" << "20" << ",c=" << "30" << "." | |
end | |
end | |
x.report("interpolation") do | |
for i in 0..30000000 do | |
str = "a=#{'10'},b=#{'20'},c=#{'30'}." | |
end | |
end | |
end |
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
-- concatenation -- | |
user system total real | |
11.753000 0.000000 11.753000 ( 11.712000) | |
-- interpolation -- | |
user system total real | |
1.796000 0.000000 1.796000 ( 1.796000) |
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
-- concatenation -- | |
user system total real | |
259.490000 3.960000 263.450000 (170.512197) | |
-- interpolation -- | |
user system total real | |
31.720000 0.560000 32.280000 ( 19.904950) |
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
-- concatenation -- | |
user system total real | |
53.250000 0.040000 53.290000 ( 53.310574) | |
-- interpolation -- | |
user system total real | |
5.150000 0.010000 5.160000 ( 5.159601) |
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
-- concatenation -- | |
user system total real | |
33.560000 0.070000 33.630000 ( 33.625422) | |
-- interpolation -- | |
user system total real | |
4.390000 0.010000 4.400000 ( 4.392276) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment