3 ms·
This test is really bad. 3 iterations? 20 iterations? Common sense says that the performance difference in these cases will be immaterial anyway barring some
by mquander 17y ago
This test is really bad. 3 iterations? 20 iterations? Common sense says that the performance difference in these cases will be immaterial anyway barring some bizarre scenario, so you should write whatever is clearer.
If you try 1000 iterations, StringBuilder will be clearly on top, and if you try 100,000 iterations, there will be no contest.
Also, the methodology in this test is completely broken. I wouldn't be surprised if the compiler partially or completely optimizes out the loops using immutable strings, since you don't use the result anywhere. To design a correct test for a micro-optimization like this you need to check the generated code in each instance (at a minimum.)
EDIT: I just noticed the strbldr.ToString() as well, which completely defeats the purpose even further. Please do more work before jumping to conclusions and publishing them to an audience. How did this make it to the front page?
- lanstein 17y agoother than that, this is an excellent, well thought-out study. ;)