3 ms·
String builder and concatenation -> use concatenation My recommendation: pick some appropriate value of n, and make it a coding standard to use it for chains o
by stcredzero 16y ago
String builder and concatenation -> use concatenation
My recommendation: pick some appropriate value of n, and make it a coding standard to use it for chains of concatenation larger than that. You can even profile this in your app, in your actual environment to pick a value of n empirically determined to be around the actual performance crossover point.
Is this pre-optimization? Debatable, if you make your decision based on profiling. The thing is, that in this case, there are a lot of places where this sort of thing can appear. A coding standard like this isn't costly, and by taking this step, you reduce a lot of memory allocation and O(n^2) inefficiency noise when you do your profiling.
Even better: JIT VMs that can optimize out chains of concatenation behind the scenes.