You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
884 B

using System.Diagnostics;
using System.Text;
namespace StringBuilderTest
{
internal class Program
{
static void Main(string[] args)
{
int cnt = 100000;
Stopwatch sw = new Stopwatch();
Console.WriteLine("Test1\tString");
sw.Start();
string s = "";
for (int i = 0; i < cnt; i++)
{
s += i;
}
sw.Stop();
Console.WriteLine($"Elapsed: {sw.ElapsedMilliseconds}ms");
Console.WriteLine("Test2\tStringBuilder");
sw.Restart();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < cnt; i++)
{
sb.Append(i);
}
sw.Stop();
Console.WriteLine($"Elapsed: {sw.ElapsedMilliseconds}ms");
}
}
}