Performance StringBuilder Insert vs. String Concat

What is more efficient in performance for adding a line to another?

Using the StringBuilder.Insert method or the string.Concat method?

messageString.Insert(0, prependedString);

or

string.Concat(prependedString, messageString);

In my case, the message line is relatively large, the added line is short.

+4
source share
2 answers

string.Concat- The fastest way if the number of elements is fixed. This statement is true in all cases. It doesn't matter how many lines are left.

string.Concatcalculates the final row size and then copies bit by bit to the fresh highlighted row. This cannot be done faster.

, a + b Concat ( ).

False. ?!

, StringBuilder

False. , Concat. StringBuilder , .

,

False. , , .

StringBuilder - . , , . . .

+6

StringBuilder, , :

Concat , StringBuilder , .

+3

Source: https://habr.com/ru/post/1608970/


All Articles