using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
int nums = 100000;
StringBuilder sb = new StringBuilder();
string str="";
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < nums; i++)
{
sb.Append("helloworld");
}
watch.Stop();
watch.Reset(); //下次watch启动前需先stop、reset后再start
string st = watch.ElapsedMilliseconds.ToString();
Console.WriteLine(st);
watch.Start();
for (int i = 0; i < nums; i++)
{
str += "helloworld";
}
watch.Stop();
string st1 = watch.ElapsedMilliseconds.ToString();
Console.WriteLine(st1);
Console.ReadKey();
}
}
}
Watch对类测量代码运行时间
最新推荐文章于 2024-09-21 22:57:45 发布