I tested a simple concatenation:
string res = "";
for (var i = 0; i < 1000; i++)
{
res += mystring;
}
return res;
and another with a StringBuilder
object:
StringBuilder builder = new StringBuilder();
for (var i = 0; i < 1000; i++)
{
builder.Append(mystring);
}
return builder.ToString();
The bigger is the cycle, the better are the performances using the StringBuilder
.
I would like to know the real reason of this result, I mean, that fact of creating, implementing an object, calling methods is faster than a simple string1 + string2
?