Last active
December 15, 2015 20:40
-
-
Save fbernier/5319833 to your computer and use it in GitHub Desktop.
Single quote vs double quote in ruby
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/ips" | |
Benchmark.ips do |x| | |
x.report("double quote assignment:") {a = "yo man"} | |
x.report("double quote +:") {|i| a = "yo man" + i.to_s} | |
x.report("double quote <<:") {|i| a = "yo man" << i.to_s} | |
x.report("double quote interpolation:") {|i| a = "yo man #{i}"} | |
x.report("single quote assignment:") {a = 'yo man'} | |
x.report("single quote +:") {|i| a = 'yo man' + i.to_s} | |
x.report("single quote <<:") {|i| a = 'yo man' << i.to_s} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Calculating -------------------------------------
double quote assignment: 124148 i/100ms
double quote +: 80580 i/100ms
double quote <<: 54579 i/100ms
double quote interpolation: 56484 i/100ms
single quote assignment: 66952 i/100ms
single quote +: 55945 i/100ms
single quote <<: 56802 i/100ms
double quote assignment: 3277829.4 (±11.1%) i/s - 16263388 in 5.009983s
double quote +: 47323167615.2 (±29.0%) i/s - 51474987480 in 1.449518s
double quote <<: 33472785772.0 (±32.8%) i/s - 36536547075 in 1.426296s
double quote interpolation: 32494962674.8 (±29.2%) i/s - 38721024648 in 1.430845s
single quote assignment: 4250543.1 (±32.0%) i/s - 19416080 in 5.015138s
single quote +: 32693506756.2 (±28.2%) i/s - 34788615020 in 1.513129s
single quote <<: 33534904560.4 (±27.7%) i/s - 38024678850 in 1.375194s