Bug #1255: += for large strings egrigiously slow
http://redmine.ruby-lang.org/issues/show/1255

Author: James Lee
Status: Open, Priority: Normal
ruby -v: ruby 1.8.6 (2008-08-11 patchlevel 287) [i686-linux] 

For small strings, += seems to have roughly the same performance as <<.  However, at some point += goes geometric and becomes amazingly slow.  Here are a few simple tests illustrating the problem:

==========
 ~ $ time ruby -e 'a = "A"; 100000.times { a << "A" }'
real    0m0.444s
user    0m0.428s
sys     0m0.016s

 ~ $ time ruby -e 'a = "A"; 1000000.times { a << "A" }'

real    0m1.760s
user    0m1.740s
sys     0m0.020s

==========
Now the same tests with +=
==========

 ~ $ time ruby -e 'a = "A"; 100000.times { a += "A" }'
real    0m15.284s
user    0m15.197s
sys     0m0.068s

 ~ $ time ruby -e 'a = "A"; 1000000.times { a += "A" }'
^C-e:1: Interrupt
        from -e:1:in `times'
        from -e:1

real    5m8.497s
user    4m59.915s
sys     0m4.844s


----------------------------------------
http://redmine.ruby-lang.org