Created
February 16, 2012 18:03
-
-
Save semmons99/1846772 to your computer and use it in GitHub Desktop.
strings: single vs. double quotes
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
$ ruby strings.rb [1.8.7-p357] | |
user system total real | |
double quote | |
assignment: 1.580000 0.000000 1.580000 ( 1.575944) | |
+: 8.750000 0.000000 8.750000 ( 8.746774) | |
<<: 9.660000 0.010000 9.670000 ( 9.668061) | |
interpolation: 8.870000 0.000000 8.870000 ( 8.869000) | |
single quote | |
assignment: 1.570000 0.000000 1.570000 ( 1.570190) | |
+: 8.580000 0.000000 8.580000 ( 8.581263) | |
<<: 9.510000 0.000000 9.510000 ( 9.504430) |
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
$ ruby strings.rb [1.9.2-p290] | |
user system total real | |
double quote | |
assignment: 1.170000 0.010000 1.180000 ( 1.175129) | |
+: 3.820000 0.000000 3.820000 ( 3.816076) | |
<<: 3.530000 0.000000 3.530000 ( 3.533197) | |
interpolation: 3.910000 0.010000 3.920000 ( 3.909262) | |
single quote | |
assignment: 1.190000 0.000000 1.190000 ( 1.188267) | |
+: 3.820000 0.000000 3.820000 ( 3.823054) | |
<<: 3.550000 0.000000 3.550000 ( 3.546011) |
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
$ ruby strings.rb [1.9.3-p0] | |
user system total real | |
double quote | |
assignment: 1.160000 0.000000 1.160000 ( 1.157568) | |
+: 3.810000 0.010000 3.820000 ( 3.808079) | |
<<: 3.520000 0.000000 3.520000 ( 3.527592) | |
interpolation: 3.600000 0.000000 3.600000 ( 3.598699) | |
single quote | |
assignment: 1.170000 0.000000 1.170000 ( 1.168748) | |
+: 3.810000 0.000000 3.810000 ( 3.807643) | |
<<: 3.520000 0.000000 3.520000 ( 3.527748) |
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
$ jruby --1.8 strings.rb [jruby-1.6.6] | |
user system total real | |
double quote | |
assignment: 0.641000 0.000000 0.641000 ( 0.612000) | |
+: 3.246000 0.000000 3.246000 ( 3.246000) | |
<<: 3.626000 0.000000 3.626000 ( 3.626000) | |
interpolation: 3.634000 0.000000 3.634000 ( 3.634000) | |
single quote | |
assignment: 0.453000 0.000000 0.453000 ( 0.453000) | |
+: 3.481000 0.000000 3.481000 ( 3.481000) | |
<<: 3.952000 0.000000 3.952000 ( 3.952000) |
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
$ jruby --1.9 strings.rb [jruby-1.6.6] | |
user system total real | |
double quote | |
assignment: 0.650000 0.000000 0.650000 ( 0.650000) | |
+: 3.315000 0.000000 3.315000 ( 3.315000) | |
<<: 3.745000 0.000000 3.745000 ( 3.745000) | |
interpolation: 3.984000 0.000000 3.984000 ( 3.984000) | |
single quote | |
assignment: 0.673000 0.000000 0.673000 ( 0.673000) | |
+: 3.668000 0.000000 3.668000 ( 3.668000) | |
<<: 3.771000 0.000000 3.771000 ( 3.771000) |
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
$ jruby --1.8 strings.rb [jruby-1.7.0-dev] | |
user system total real | |
double quote | |
assignment: 0.654000 0.000000 0.654000 ( 0.633000) | |
+: 2.482000 0.000000 2.482000 ( 2.482000) | |
<<: 2.725000 0.000000 2.725000 ( 2.725000) | |
interpolation: 2.878000 0.000000 2.878000 ( 2.878000) | |
single quote | |
assignment: 0.438000 0.000000 0.438000 ( 0.438000) | |
+: 2.618000 0.000000 2.618000 ( 2.618000) | |
<<: 2.683000 0.000000 2.683000 ( 2.683000) |
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
$ jruby --1.9 strings.rb [jruby-1.7.0-dev] | |
user system total real | |
double quote | |
assignment: 0.598000 0.000000 0.598000 ( 0.598000) | |
+: 2.662000 0.000000 2.662000 ( 2.662000) | |
<<: 2.998000 0.000000 2.998000 ( 2.999000) | |
interpolation: 3.354000 0.000000 3.354000 ( 3.353000) | |
single quote | |
assignment: 0.691000 0.000000 0.691000 ( 0.691000) | |
+: 2.885000 0.000000 2.885000 ( 2.885000) | |
<<: 2.942000 0.000000 2.942000 ( 2.943000) |
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
$ rbx -X18 strings.rb [rbx-2.0.0-dev] | |
user system total real | |
double quote | |
assignment: 0.938289 0.001547 0.939836 ( 0.936368) | |
+: 17.999834 0.015982 18.015816 ( 17.800602) | |
<<: 6.961730 0.002337 6.964067 ( 6.931812) | |
interpolation: 3.436320 0.001012 3.437332 ( 3.434079) | |
single quote | |
assignment: 0.663528 0.000734 0.664262 ( 0.661843) | |
+: 16.606219 0.002503 16.608722 ( 16.602140) | |
<<: 6.676738 0.001487 6.678225 ( 6.646201) |
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
$ rbx -X19 strings.rb [rbx-2.0.0-dev] | |
user system total real | |
double quote | |
assignment: 1.121872 0.005459 1.127331 ( 1.014410) | |
+: 28.878727 0.007471 28.886198 ( 28.631753) | |
<<: 14.368631 0.004824 14.373455 ( 14.334715) | |
interpolation: 3.533245 0.002682 3.535927 ( 3.530677) | |
single quote | |
assignment: 0.714519 0.000244 0.714763 ( 0.710089) | |
+: 28.628334 0.010575 28.638909 ( 28.672013) | |
<<: 14.553449 0.014743 14.568192 ( 14.529628) |
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" | |
Benchmark.bm(14) do |x| | |
puts "double quote" | |
x.report("assignment:") { 10_000_000.times{ a = "hey man"} } | |
x.report("+:") { 10_000_000.times{|i| a = "hey man" + i.to_s} } | |
x.report("<<:") { 10_000_000.times{|i| a = "hey man" << i.to_s} } | |
x.report("interpolation:") { 10_000_000.times{|i| a = "hey man #{i}"} } | |
puts "single quote" | |
x.report("assignment:") { 10_000_000.times{ a = 'hey man'} } | |
x.report("+:") { 10_000_000.times{|i| a = 'hey man' + i.to_s} } | |
x.report("<<:") { 10_000_000.times{|i| a = 'hey man' << i.to_s} } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment