110,557
社区成员
发帖
与我相关
我的任务
分享
int tnum = 100000; // 添加或查找的次数
int outnum = 10; // 外层循环次数
List<string> arr = new List<string>();
for(int i=0;i<tnum;i++)
arr.Add(i.ToString());
string[] arr2 = new string[tnum];
for(int j=0;j<outnum;j++)
{
Stopwatch watch = new Stopwatch();
string msg;
msg = "Number ";
watch.Reset();
watch.Start();
for (int i = 0, h = arr.Count; i < h; i++)
{
}
watch.Stop();
Console.WriteLine(msg + "耗时:" + watch.ElapsedTicks.ToString());
msg = ".Count ";
watch.Reset();
watch.Start();
for (int i = 0; i < arr.Count; i++)
{
}
watch.Stop();
Console.WriteLine(msg + "耗时:" + watch.ElapsedTicks.ToString());
msg = "Length ";
watch.Reset();
watch.Start();
for (int i = 0; i < arr2.Length; i++)
{
}
watch.Stop();
Console.WriteLine(msg + "耗时:" + watch.ElapsedTicks.ToString());
}