using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class ClearStringBuilder { static void Main(string[] args) { int i = 0; const int max = 50000000; int tick = Environment.TickCount; for (i = 0; i < max; i++) { StringBuilder sb = new StringBuilder("test"); sb.Clear(); } Console.WriteLine(Environment.TickCount - tick); tick = Environment.TickCount; for (i = 0; i < max; i++) { StringBuilder sb = new StringBuilder("test"); sb.Remove(0, sb.Length); } Console.WriteLine(Environment.TickCount - tick); tick = Environment.TickCount; for (i = 0; i < max; i++) { StringBuilder sb = new StringBuilder("test"); string s = sb.ToString(); sb.Replace(s, ""); } Console.WriteLine(Environment.TickCount - tick); tick = Environment.TickCount; for (i = 0; i < max; i++) { StringBuilder sb = new StringBuilder(); sb.Length = 0; } Console.WriteLine(Environment.TickCount - tick); } } }