Best Collection for Fast String Lookup

后端 未结 7 1600
别跟我提以往
别跟我提以往 2020-12-30 22:28

I need a list of strings and a way to quickly determine if a string is contained within that list.

To enhance lookup speed, I considered SortedList and

相关标签:
7条回答
  • 2020-12-30 23:09

    I know this answer is a bit late to this party, but I was running into an issue where our systems were running slow. After profiling we found out there was a LOT of string lookups happening with the way we had our data structures structured.

    So we did some research, came across these benchmarks, did our own tests, and have switched over to using SortedList now.

    if (sortedlist.ContainsKey(thekey))
    {   
    //found it.
    }
    

    Even though a Dictionary proved to be faster, it was less code we had to refactor, and the performance increase was good enough for us.

    Anyway, wanted to share the website in case other people are running into similar issues. They do comparisons between data structures where the string you're looking for is a "key" (like HashTable, Dictionary, etc) or in a "value" (List, Array, or in a Dictionary, etc) which is where ours are stored.

    0 讨论(0)
提交回复
热议问题