I am amazed at how fast character arrays are compared to their string alternatives in every programming language I’ve ever used. This shouldn’t be a huge surprise but I thought I’d point out that by switching from Standard Template Library strings to char arrays in C++ on a project I’ve got going things sped up from around 25 seconds to process 55,000 lines of files to 15 seconds. Furthermore, in Java, using threading and database insertion on a previous project I was able to get even more performance increases (it was an older version of the runtime, and I switched from String to StringBuffer, which is basically an array). In JavaScript, If you have to accumulate characters into a buffer, I strongly recommend using an array and either push
ing the data (if you can afford to not support IE 5) or using arrayVar[arrayVar.length] = value;
.
By learning to think this way you’ll have faster code out of the box, which is always nice because it means you don’t have to spend time refactoring. You do refactor, don’t you?
Thanks to Tony Nuzzi for the String->StringBuffer conversion in Java, and Craig Kaes for helping me to better understand char *pointers and char arrays a little better.