Created
May 7, 2013 14:11
-
-
Save deadkarma/5532846 to your computer and use it in GitHub Desktop.
String performance
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' | |
n = 1000000 | |
Benchmark.bmbm do |x| | |
x.report("assign single") { n.times do; c = 'a string'; end} | |
x.report("assign double") { n.times do; c = "a string"; end} | |
x.report("concat single") { n.times do; 'a string ' + 'b string'; end} | |
x.report("concat double") { n.times do; "a string " + "b string"; end} | |
x.report("use << single") { n.times do; 'a string ' << 'b string'; end} | |
x.report("use << double") { n.times do; "a string " << "b string"; end} | |
x.report("use interpola") { n.times do; "a string #{'b_string'}"; end} | |
end |
Author
deadkarma
commented
May 7, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment