stringbuilder和string拼字符串的性能,有点吓人。

代码
           System.Text.StringBuilder sb = new System.Text.StringBuilder();
            
int i = 0;
            
long StartTime = DateTime.Now.Ticks;
            
while (i < 80000)
            {
                sb.Append(i.ToString());
                i
++;
            }
            
long EndTime = DateTime.Now.Ticks;

            Console.WriteLine(
"时间:" + (EndTime - StartTime) + "\t Capacity:" + sb.Capacity + "\t Length:"

            
+ sb.Length);


            
string sb1 = null;
            i 
= 0;
            StartTime 
= DateTime.Now.Ticks;
            
while (i < 80000)
            {
                sb1 
+= i;
                i
++;
            }
            EndTime 
= DateTime.Now.Ticks;
            Console.WriteLine(
"时间:" + (EndTime - StartTime));
            Console.Read();

 

posted @ 2010-01-03 14:19  小白.net  阅读(395)  评论(0编辑  收藏  举报