var users = new List<UserInfo>();
for (int i = 0; i < 100000; i++)
{
users.Add(new UserInfo
{
ID = i,
Name = "张三" + i.ToString(),
Age = "16",
Remark = "",
});
}
var userinfos = new List<UserInfo>();
for (int i = 0; i < 60000; i++)
{
userinfos.Add(new UserInfo
{
ID = 1,
Name = "张三daasd",
Age = "26",
Remark = "",
});
}
//Console.WriteLine(DateTime.Now.ToString());
//release:21秒
//foreach (var userInfo in users)
//{
// var m = userinfos.FindAll(o => o.ID == userInfo.ID);
//}
//release:23秒
//for (int i = 0; i < users.Count; i++)
//{
// var m = userinfos.FindAll(o => o.ID == users[i].ID);
//}
//release:14秒(CollectionsMarshal.AsSpan 无敌)
//foreach (var userInfo in CollectionsMarshal.AsSpan(users))
//{
// var m = userinfos.FindAll(o => o.ID == userInfo.ID);
//}
//Console.WriteLine(DateTime.Now.ToString());
标签:users,C#,userinfos,循环,userInfo,var,new,优化,ID From: https://www.cnblogs.com/wangtiantian/p/17562223.html