Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using a list of 2,000,000 items and i am having to search it for individual items. This is taking me 5 minutes+. Currently using this Code:

C#
List<MyType> results = GetList();

MyType item = results.Find(item => item.name == "test");


Obviously this speed is unacceptable, I am just wondering what i can do to improve this.

What would be the best way to store/search this data?

Thanks
Carl
Posted
Comments
CHill60 29-Sep-14 12:47pm    
Why not store the data on a database and just query for the item you want?
Sergey Alexandrovich Kryukov 29-Sep-14 12:52pm    
There are many ways to accelerate the search using some redundant data. But to advise, I would need to know the purpose of all that. Are there any unique properties of an item? And so on...
—SA

Change it to a for each loop. In the speed test I have done LINQ was always the slowest by a large margin.
C#
foreach (MyType item in results) {
	if (string.Compare(item.name, "test", true) == 0) {
		//Do Something.
	}
}
 
Share this answer
 
Comments
Maciej Los 29-Sep-14 14:18pm    
Are you sure, that loop is faster then LINQ? Based on my experience, linq is really fast.
I believe it depends on many factors...

There are few ways to Increase LINQ Query Performance[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900