Created
May 28, 2019 13:39
-
-
Save rmm5t/bfd42a3089a7c7d2df8ca410784c1e60 to your computer and use it in GitHub Desktop.
Revisions
-
rmm5t created this gist
May 28, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ require 'benchmark' def test_interpolation(x, y) "X#{x}Y#{y}" end def test_join(x, y) ["X", x, "Y", y].join end n = 100_000 Benchmark.bmbm(15) do |x| x.report("String interpolation") { n.times { test_interpolation(1, 2) } } x.report("Array#join") { n.times { test_join(1, 2) } } end # >> user system total real # >> String interpolation 0.030083 0.000099 0.030182 ( 0.030252) # >> Array#join 0.080881 0.000200 0.081081 ( 0.081173)