<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: StringBuilder is not always faster &#8211; Part 1 of 2</title>
	<atom:link href="http://www.chinhdo.com/20070224/stringbuilder-is-not-always-faster/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chinhdo.com/20070224/stringbuilder-is-not-always-faster/</link>
	<description>Chinh's not quite random thoughts on software development, .NET, gadgets, and other things.</description>
	<lastBuildDate>Tue, 09 Mar 2010 13:15:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Trevor</title>
		<link>http://www.chinhdo.com/20070224/stringbuilder-is-not-always-faster/comment-page-1/#comment-49558</link>
		<dc:creator>Trevor</dc:creator>
		<pubDate>Wed, 08 Jul 2009 00:36:59 +0000</pubDate>
		<guid isPermaLink="false">http://vienxu.com/chinh/blog/20070224/stringbuilder-is-not-always-faster/#comment-49558</guid>
		<description>Use a MemoryProfiler to see which one is better</description>
		<content:encoded><![CDATA[<p>Use a MemoryProfiler to see which one is better</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chinh Do</title>
		<link>http://www.chinhdo.com/20070224/stringbuilder-is-not-always-faster/comment-page-1/#comment-41897</link>
		<dc:creator>Chinh Do</dc:creator>
		<pubDate>Fri, 24 Apr 2009 11:17:47 +0000</pubDate>
		<guid isPermaLink="false">http://vienxu.com/chinh/blog/20070224/stringbuilder-is-not-always-faster/#comment-41897</guid>
		<description>Marvin: Good question. Thanks. I am curious about it too so I decided to run some measurements again. My result indicates that doing the initialization like you suggested will save some time off of the StringBuilder result. However it was not enough to be faster than the string test. Seems like it would be a good idea to always seed the initial value as part of the construction if you can do it.

Chinh</description>
		<content:encoded><![CDATA[<p>Marvin: Good question. Thanks. I am curious about it too so I decided to run some measurements again. My result indicates that doing the initialization like you suggested will save some time off of the StringBuilder result. However it was not enough to be faster than the string test. Seems like it would be a good idea to always seed the initial value as part of the construction if you can do it.</p>
<p>Chinh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marvin</title>
		<link>http://www.chinhdo.com/20070224/stringbuilder-is-not-always-faster/comment-page-1/#comment-41703</link>
		<dc:creator>Marvin</dc:creator>
		<pubDate>Thu, 23 Apr 2009 05:38:39 +0000</pubDate>
		<guid isPermaLink="false">http://vienxu.com/chinh/blog/20070224/stringbuilder-is-not-always-faster/#comment-41703</guid>
		<description>&#039;###
This block of code took 1484 milliseconds to run on my PC:

for (int i = 0; i &lt;= 1000000; i++)
{
    // Concat strings 3 times using StringBuilder
    StringBuilder s = new StringBuilder();
    s.Append(i.ToString());
    s.Append(i.ToString());
    s.Append(i.ToString());
}

And this one, using traditional concatenation, took slightly less time (1344 milliseconds):

for (int i = 0; i &lt;= 1000000; i++)
{
    // Concat strings 3 times using traditional concatenation
    string s = i.ToString();
    s = s + i.ToString();
    s = s + i.ToString();
}

The above data suggests that StringBuilder only starts to work faster once the number of concatenations exceed 3.
&#039;###

I noticed in the &#039;string&#039; example you initialize s with the first string. Would StringBuilder be equivalent or faster for 3 concatenations if you initialized stringbuilder also with the first string? e.g. result in 3 lines instead of 4:

    StringBuilder s = new StringBuilder(i.ToString(),16);
    s.Append(i.ToString());
    s.Append(i.ToString());

*Note StringBuilder Initializer includes default size of 16, otherwise it would be reallocating memory with each append since the size would also initialize to 1.</description>
		<content:encoded><![CDATA[<p>&#8216;###<br />
This block of code took 1484 milliseconds to run on my PC:</p>
<p>for (int i = 0; i &lt;= 1000000; i++)<br />
{<br />
    // Concat strings 3 times using StringBuilder<br />
    StringBuilder s = new StringBuilder();<br />
    s.Append(i.ToString());<br />
    s.Append(i.ToString());<br />
    s.Append(i.ToString());<br />
}</p>
<p>And this one, using traditional concatenation, took slightly less time (1344 milliseconds):</p>
<p>for (int i = 0; i &lt;= 1000000; i++)<br />
{<br />
    // Concat strings 3 times using traditional concatenation<br />
    string s = i.ToString();<br />
    s = s + i.ToString();<br />
    s = s + i.ToString();<br />
}</p>
<p>The above data suggests that StringBuilder only starts to work faster once the number of concatenations exceed 3.<br />
&#8216;###</p>
<p>I noticed in the &#8217;string&#8217; example you initialize s with the first string. Would StringBuilder be equivalent or faster for 3 concatenations if you initialized stringbuilder also with the first string? e.g. result in 3 lines instead of 4:</p>
<p>    StringBuilder s = new StringBuilder(i.ToString(),16);<br />
    s.Append(i.ToString());<br />
    s.Append(i.ToString());</p>
<p>*Note StringBuilder Initializer includes default size of 16, otherwise it would be reallocating memory with each append since the size would also initialize to 1.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chinh Do</title>
		<link>http://www.chinhdo.com/20070224/stringbuilder-is-not-always-faster/comment-page-1/#comment-41294</link>
		<dc:creator>Chinh Do</dc:creator>
		<pubDate>Mon, 20 Apr 2009 22:09:00 +0000</pubDate>
		<guid isPermaLink="false">http://vienxu.com/chinh/blog/20070224/stringbuilder-is-not-always-faster/#comment-41294</guid>
		<description>Michael: That makes a lot of sense. Thanks.</description>
		<content:encoded><![CDATA[<p>Michael: That makes a lot of sense. Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.chinhdo.com/20070224/stringbuilder-is-not-always-faster/comment-page-1/#comment-41287</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Mon, 20 Apr 2009 19:12:37 +0000</pubDate>
		<guid isPermaLink="false">http://vienxu.com/chinh/blog/20070224/stringbuilder-is-not-always-faster/#comment-41287</guid>
		<description>If .Net handles String and StringBuilder like Java does, the reason that 3 is the break even point has to do with object creation.  With 3 concatenations, each method creates 5 objects (by my count).

StringBuilder:
1 StringBuilder
3 Strings for input
1 String for the final result

Concatenation:
3 Strings for input
1 String for the result of the concatenation of String 2 + 3
1 String for the result of the concatenation of String 1 and the above</description>
		<content:encoded><![CDATA[<p>If .Net handles String and StringBuilder like Java does, the reason that 3 is the break even point has to do with object creation.  With 3 concatenations, each method creates 5 objects (by my count).</p>
<p>StringBuilder:<br />
1 StringBuilder<br />
3 Strings for input<br />
1 String for the final result</p>
<p>Concatenation:<br />
3 Strings for input<br />
1 String for the result of the concatenation of String 2 + 3<br />
1 String for the result of the concatenation of String 1 and the above</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: YuzeroK</title>
		<link>http://www.chinhdo.com/20070224/stringbuilder-is-not-always-faster/comment-page-1/#comment-3173</link>
		<dc:creator>YuzeroK</dc:creator>
		<pubDate>Fri, 14 Mar 2008 11:23:56 +0000</pubDate>
		<guid isPermaLink="false">http://vienxu.com/chinh/blog/20070224/stringbuilder-is-not-always-faster/#comment-3173</guid>
		<description>Хороший заработок в интернете. Нужно покоментировать страницы, которые вам откроют после регистрации, и за это платят денги и не малые. Я лично зарабатываю около 500$ в месяц. 
 
Регистрируемся тут &lt;a href=&quot;http://www.AWSurveys.com/HomeMain.cfm?RefID=yuzerok&quot; rel=&quot;nofollow&quot;&gt;awsurveys.com&lt;/a&gt; 
 
1.Нажимите Create A Free Account 
 
UserName - имя пользователя 
Password - пароль 7-15 знаков 
First Name - имя 
Last Name - Фамилия 
Email Address - почтовый ящик 
Далее вводим цифорки-буковки, нажимаем кнопку Create A Free Account 
Вы зарегистрировались! 
 
2.Далее видим таблицу, имеющую такой вид: 
 
The Following Surveys are Available: 
Welcome Survey -- A $6.00 Website Evaluation is Available. 
A $4.00 Website Evaluation is Available. 
A $4.00 Website Evaluation is Available. 
A $4.00 Website Evaluation is Available. 
A $4.00 Website Evaluation is Available. 
A $4.00 Website Evaluation is Available. 
 
3.Щелкаем по одной из ссылок на этой странице, попадаем на следущюю страницу и там щелкаем по надписи &quot;Start Survey Now&quot; 
 
4.Здесь 2 ссылки и 2 поля, в них нужно написать отзыв о сайте на англ языке. 
 
(пример: It is an excellent site, I shall advise its all, this is good job, it&#039;s very usefull web-resource и т.п) 
 
5.Щелкае по кнопке внизу &quot;Click to submit ...&quot; Щелкаем по ссылке &quot;Click Here to go Home and...&quot; 
 
6.И так далее по ссылкам и так каждый день. 
 
7.Для вывода денег воспользуйтесь кнопкой &quot;Redeem Money&quot; 
выводятся деньги в системе PayPal (легко переводятся в вебмани) 
могу помочь тем кто не знаком с электронными платежными системами</description>
		<content:encoded><![CDATA[<p>Хороший заработок в интернете. Нужно покоментировать страницы, которые вам откроют после регистрации, и за это платят денги и не малые. Я лично зарабатываю около 500$ в месяц. </p>
<p>Регистрируемся тут <a href="http://www.AWSurveys.com/HomeMain.cfm?RefID=yuzerok" rel="nofollow">awsurveys.com</a> </p>
<p>1.Нажимите Create A Free Account </p>
<p>UserName &#8211; имя пользователя<br />
Password &#8211; пароль 7-15 знаков<br />
First Name &#8211; имя<br />
Last Name &#8211; Фамилия<br />
Email Address &#8211; почтовый ящик<br />
Далее вводим цифорки-буковки, нажимаем кнопку Create A Free Account<br />
Вы зарегистрировались! </p>
<p>2.Далее видим таблицу, имеющую такой вид: </p>
<p>The Following Surveys are Available:<br />
Welcome Survey &#8212; A $6.00 Website Evaluation is Available.<br />
A $4.00 Website Evaluation is Available.<br />
A $4.00 Website Evaluation is Available.<br />
A $4.00 Website Evaluation is Available.<br />
A $4.00 Website Evaluation is Available.<br />
A $4.00 Website Evaluation is Available. </p>
<p>3.Щелкаем по одной из ссылок на этой странице, попадаем на следущюю страницу и там щелкаем по надписи &#8220;Start Survey Now&#8221; </p>
<p>4.Здесь 2 ссылки и 2 поля, в них нужно написать отзыв о сайте на англ языке. </p>
<p>(пример: It is an excellent site, I shall advise its all, this is good job, it&#8217;s very usefull web-resource и т.п) </p>
<p>5.Щелкае по кнопке внизу &#8220;Click to submit &#8230;&#8221; Щелкаем по ссылке &#8220;Click Here to go Home and&#8230;&#8221; </p>
<p>6.И так далее по ссылкам и так каждый день. </p>
<p>7.Для вывода денег воспользуйтесь кнопкой &#8220;Redeem Money&#8221;<br />
выводятся деньги в системе PayPal (легко переводятся в вебмани)<br />
могу помочь тем кто не знаком с электронными платежными системами</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 1kHz &#124; anti-keseronokan &#187; Blog Archive &#187; String Concatenation dan Performance</title>
		<link>http://www.chinhdo.com/20070224/stringbuilder-is-not-always-faster/comment-page-1/#comment-503</link>
		<dc:creator>1kHz &#124; anti-keseronokan &#187; Blog Archive &#187; String Concatenation dan Performance</dc:creator>
		<pubDate>Sun, 30 Sep 2007 03:26:07 +0000</pubDate>
		<guid isPermaLink="false">http://vienxu.com/chinh/blog/20070224/stringbuilder-is-not-always-faster/#comment-503</guid>
		<description>[...] StringBuilder is not always faster StringBuilder is not always faster - Part 2 [...]</description>
		<content:encoded><![CDATA[<p>[...] StringBuilder is not always faster StringBuilder is not always faster &#8211; Part 2 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chinh Do</title>
		<link>http://www.chinhdo.com/20070224/stringbuilder-is-not-always-faster/comment-page-1/#comment-501</link>
		<dc:creator>Chinh Do</dc:creator>
		<pubDate>Sat, 29 Sep 2007 06:39:02 +0000</pubDate>
		<guid isPermaLink="false">http://vienxu.com/chinh/blog/20070224/stringbuilder-is-not-always-faster/#comment-501</guid>
		<description>Hello all, I have posted a &lt;a href=&quot;http://www.chinhdo.com/chinh/blog/20070929/stringbuilder-part-2/&quot; rel=&quot;nofollow&quot;&gt;follow-up article&lt;/a&gt; to provide more detailed analysis and to answer some of the questions asked by readers.</description>
		<content:encoded><![CDATA[<p>Hello all, I have posted a <a href="http://www.chinhdo.com/chinh/blog/20070929/stringbuilder-part-2/" rel="nofollow">follow-up article</a> to provide more detailed analysis and to answer some of the questions asked by readers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: StringBuilder is not always faster - Part 2 &#187; Chinh Do</title>
		<link>http://www.chinhdo.com/20070224/stringbuilder-is-not-always-faster/comment-page-1/#comment-499</link>
		<dc:creator>StringBuilder is not always faster - Part 2 &#187; Chinh Do</dc:creator>
		<pubDate>Sat, 29 Sep 2007 06:19:55 +0000</pubDate>
		<guid isPermaLink="false">http://vienxu.com/chinh/blog/20070224/stringbuilder-is-not-always-faster/#comment-499</guid>
		<description>[...] a previous article (&#8221;StringBuilder is not always faster), I provided some quick benchmark data and gave &#8220;rules of thumb&#8221; for when to use [...]</description>
		<content:encoded><![CDATA[<p>[...] a previous article (&#8221;StringBuilder is not always faster), I provided some quick benchmark data and gave &#8220;rules of thumb&#8221; for when to use [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Weekly Link Post 8 &#171; Rhonda Tipton&#8217;s WebLog</title>
		<link>http://www.chinhdo.com/20070224/stringbuilder-is-not-always-faster/comment-page-1/#comment-430</link>
		<dc:creator>Weekly Link Post 8 &#171; Rhonda Tipton&#8217;s WebLog</dc:creator>
		<pubDate>Sun, 23 Sep 2007 22:26:33 +0000</pubDate>
		<guid isPermaLink="false">http://vienxu.com/chinh/blog/20070224/stringbuilder-is-not-always-faster/#comment-430</guid>
		<description>[...] Do&#160;has posted two&#160;good articles this week: StringBuilder is not always faster ~&#160;11 VS 2005 IDE [...]</description>
		<content:encoded><![CDATA[<p>[...] Do&nbsp;has posted two&nbsp;good articles this week: StringBuilder is not always faster ~&nbsp;11 VS 2005 IDE [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
