From: Joshua Ball Date: 2009-06-18T02:06:59+09:00 Subject: String += vs << --000e0cd331dcaa640b046c8e5132 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit A friend recently sent me this article: http://blog.metasploit.com/2009/03/blog-post.html In particular, note the perf difference of += vs << : framework3 $ time ruby -e 'a = "A"; 100000.times { a << "A" }' > > real 0m*0.338s* > user 0m*0.312s* > sys 0m0.024s > > framework3 $ time ruby -e 'a = "A"; 100000.times { a += "A" }' > > real 0m*15.462s* > user 0m*15.321s* > sys 0m0.068s Also note: *Before you run off and change every instance of += to << in your ruby code*, > it's important to note that the two don't perform the same operation. > Because ruby does assignment by reference, the latter overwrites any > variables that point to the one you're operating on while the former leaves > any references untouched. > > > framework3 $ irb > >> a = "A" > => "A" > >> b = a > => "A" > >> a << "B" > => "AB" > >> b > => "AB" >> c = "C" > => "C" > >> d = c > => "C" > >> c += "D" > => "CD" > >> d > => "C" > Thought I would pass it along... --000e0cd331dcaa640b046c8e5132--