C# String Performance
In C# I have read a lot of debate over which way is the best way to do String Concatenation. I have often read never ever use String1 + String2 due to the memory allocations and time constraints. I decided to run some tests on the various way of doing String manipulation. The table below shows the iterations, total times, and average times for some common way of doing string addition. This was just a test of time, there was no memory consumption test. All tests were doing adding 7 strings together that were stored in variable names. There was no string a = "a" + "b"; It was all string a = var1 + var2; These were creating a single string for the listed iterations using the method(s) below.
I was surprised to see the + method came out ahead in all the tests. String builder came in a close second. String.Format was extremely slow but allows for localization which is another story.