Wednesday, June 27, 2007

Appending text in Ruby

My coworker was just appending some text in Ruby and found something out:

While using the syntax '+=' the process of appending text took 1.8 seconds for this particular case. However, adding the text to an array and then converting the array to text took ~.9 seconds - almost a second difference. On further investigation the syntax '<<' also took ~.9 seconds.

In summary, use '<<' and not '+='

No comments: