LINQ Performance for Large Collections

前端 未结 6 1716
梦毁少年i
梦毁少年i 2021-02-02 11:48

I have a large collection of strings (up to 1M) alphabetically sorted. I have experimented with LINQ queries against this collection using HashSet, SortedDictionary, and Dictio

6条回答
  •  别那么骄傲
    2021-02-02 11:57

    If you are trying to optimize looking up a list of strings with a given prefix you might want to take a look at implementing a Trie (not to be mistaken with a regular tree) data structure in C#.

    Tries offer very fast prefix lookups and have a very small memory overhead compared to other data structures for this sort of operation.

    About LINQ to Objects in general. It's not unusual to have a speed reduction compared to SQL. The net is littered with articles analyzing its performance.

提交回复
热议问题