Hello Greg,
There
http://groups.google.com/group/micr.../f94bf27c8cbc912e?hl=en&#doc_6d8fc6a2b950ddad
but a bit bigger number of string.
I'm not declaring that SB doesn't hinder the performance. It really hinders,
but we need to understand where this hindering is important.
We can concantinate 10,000 string with SB for 0.09sec and this doesn hurts
us in one app, and use SB to concat 6 string where performance will be hurted
severe.
Everything depends on your context
I'm for the simplicity if we are not struggle for the additional couple of
secs
GY> I would like to see this sample showing the difference is
GY> insignificant until 25000 strings as this is in fact not the case
GY> ...
GY>
GY> public static void TenThousandWithString() {
GY> string s = "";
GY> for (int i = 0; i < 10000; i++) {
GY> s += i.ToString();
GY> }
GY> DummyString = s;
GY> }
GY>
GY> public static void TenThousandWithStringBuilder() {
GY> StringBuilder s = new StringBuilder(50000);
GY> for (int i = 0; i < 10000; i++) {
GY> s.Append(i.ToString());
GY> }
GY> DummyString = s.ToString();
GY> }
GY> for 1000 runs ...
GY>
GY> Test : String took 190539874570.188 ns, average ns =
GY> 190539874.570188 Test : StringBuilder took 3698780828.64676 ns,
GY> average ns = 3698780.82864676
GY>
GY> I would say that being 60 times faster is fairly noticable wouldn't
GY> you?
GY>
GY> at 1000 concats its still 5 times faster... and these are small
GY> strings ... with bigger strings the speed difference increases.
GY>
GY> Cheers,
GY>
GY> Greg Young
GY> MVP - C#
GY>
http://codebetter.com/blogs/gregyoung
GY> GY>---
WBR,
Michael Nemtsev :: blog:
http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche