It depends entirely on the amount of data you have stored.
它完全取决于您存储的数据量。
Assuming you have enough memory to throw at it (so the hash table is big enough), the hash table will locate the target data in a fixed amount of time, but the need to calculate the hash will add some (also fixed) overhead.
假设你有足够的内存来抛出它(所以哈希表足够大),哈希表将在固定的时间内定位目标数据,但是计算哈希值的需要会增加一些(也是固定的)开销。
Searching a sorted list won't have that hashing overhead, but the time required to do the work of actually locating the target data will increase as the list grows.
搜索排序列表不会产生散列开销,但实际定位目标数据所需的时间将随着列表的增长而增加。
So, in general, a sorted list will generally be faster for small data sets. (For extremely small data sets which are frequently changed and/or infrequently searched, an unsorted list may be even faster, since it avoids the overhead of doing the sort.) As the data set becomes large, the growth of the list's search time overshadows the fixed overhead of hashing, and the hash table becomes faster.
因此,通常,对于小数据集,排序列表通常会更快。 (对于经常更改和/或不经常搜索的非常小的数据集,未排序的列表可能更快,因为它避免了进行排序的开销。)随着数据集变大,列表的搜索时间增长过大散列的固定开销,哈希表变得更快。
Where that breakpoint is will vary depending on your specific hash table and sorted-list-search implementations. Run tests and benchmark performance on a number of typically-sized data sets to see which will actually perform better in your particular case. (Or, if the code already runs "fast enough", don't. Just use whichever you're more comfortable with and don't worry about optimizing something which doesn't need to be optimized.)
断点的位置将根据您的特定哈希表和sorted-list-search实现而有所不同。在许多通常大小的数据集上运行测试和基准测试性能,以查看在特定情况下哪些实际上会更好。 (或者,如果代码已经“足够快”运行,请不要。只需使用您感觉更舒服的东西,不要担心优化不需要优化的东西。)