[英]Performance between search in List<> and Query
我使用SDK從Staging
到Microsoft Dynamic CRM
進行數據遷移,但我對速度性能有疑問。
我在使用List<>
和SQL Query
搜索現有數據的性能之間存在一些疑問。
我的問題是
List<>
搜索現有數據和Query from DataBase
逐行Query from DataBase
比較快( 在列表中約有100,000個對象或在數據庫中有100,000個記錄 )。如果使用此方法,請立即連接數據庫。 index
應該比在對象列表中搜索更快? 但是如果我使用查詢來搜索現有數據(100,000條記錄),則必須打開並查詢100,000次 謝謝。
示例(顯然,您想對此進行優化-這只是一個想法):
private Dictionary<string, HashSet<person>> peopleList = new Dictionary<string, HashSet<person>>();
public void loadPeople()
{
List<person> people = new List<person>();
people.Add(new person() { firstName = "Shirley", lastName = "Kotarski", age = 45 });
people.Add(new person() { firstName = "Bob", lastName = "Smith", age = 24 });
people.Add(new person() { firstName = "Bill", lastName = "Jones", age = 32 });
people.Add(new person() { firstName = "Jim", lastName = "Hostettler", age = 19 });
people.Add(new person() { firstName = "Ralph", lastName = "Billings", age = 27 });
people.Add(new person() { firstName = "Eddir", lastName = "Johnson", age = 58 });
for (int i = 65; i < 91; i++)
{//Partitions based on first letter of first name
string charI = ((char)i).ToString();
string key = charI;
peopleList.Add(key, new HashSet<person>(people.Where(p => p.firstName.Substring(0, 1) == charI).ToArray()));
}
}
public void processListOfPeople()
{
for (int i = 65; i < 91; i++)
{
string charI = ((char)i).ToString();
string key = charI;
List<person> people = peopleList[key].ToList();
}
}
public person lookupPerson(string firstName)
{
person p = new so_Win.person();
string key = firstName.Substring(0, 1);
return peopleList[key].Where(m => m.firstName == firstName).ToArray()[0];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.