gpt4 book ai didi

c# - 使用多个词典或一个大词典

转载 作者:太空宇宙 更新时间:2023-11-03 19:06:25 25 4
gpt4 key购买 nike

我有一个关于 C# 字典的一般性问题。假设我读入一个文本文件,将其拆分为键和值并将它们存储在字典中。将它们全部放入一个字典或将其拆分成更小的字典会更有用吗?它可能不会对小文本文件产生太大影响,但其中一些文件超过 100.000 行。你会推荐什么?

最佳答案

首要规则始终是在尝试优化之前进行基准测试。话虽如此,有些人可能已经为您完成了基准测试。检查那些 results here

来自文章(以防万一它从网上消失了)

The smaller Dictionary (with half the number of keys) was much faster.In this case, the behavior of both Dictionaries on the input wasidentical. This means that having unneeded keys in the Dictionarymakes it slower.

My perspective is that you should use separate Dictionaries forseparate purposes. If you have two sets of keys, do not store them inthe same Dictionary. If you can divide them up, you can enhance lookupperformance.

Credit: dotnetperls.com

也来自文章:

Full Dictionary: 791 ms
Half-size Dictionary: 591 ms [faster]

也许你可以接受更少的代码和更多的 200 毫秒,这真的取决于你的应用程序

关于c# - 使用多个词典或一个大词典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26669973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com