?
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Mark said:I don't require a concrete guarantee - just some idea of the number of
iterations. If there are a lot of iterations, StringBuilder is the best
choice - agreed. I'm just questioning how many times that happens. My
definition of "a lot" is the same as yours, I suspect - where performance
degradation is noticeable.
It's not only a question of performance, but also about scalability.
Systems tend to grow over time, so many times it's better to choose a
method that scales well rather than a method that performs well when
testing with a certain amount of data.
If you have ten strings, using Concat might be faster than using a
StringBuilder. Even if you have 20 string, perhaps even 30. After that
it starts getting bad, and fast. Every single additional string means
that you use twice as much memory to concatenate them.
As long as you don't have much data, performance isn't really a problem
anyway. It's when the data starts to grow that it shows if you are able
to write scalable code.