我将创建一个将使用字典查找和插入相当多的项目.这是值得关注的吗?
此外,如果我进行基准测试等并且它确实很糟糕,那么用其他东西替换字典的最佳方法是什么?使用带有"散列"键的数组会更快吗?那会对插入时间有所帮助吗?
另外,我认为我不是微优化,因为这确实是生产服务器上代码的重要组成部分,因此如果需要额外100毫秒才能完成,那么我们将寻找新的方法来处理这个问题.
我最近一直在用C#测试C5系列,我很喜欢它们的功能.对于大型馆藏,性能似乎与通用同行相当.对于小型集合,它们的速度要慢得多.我怀疑相对速度的急剧恶化来自于C5系列的恒定时间操作.我所知道的一项行动就是解雇事件.这可能是小型收藏品表现不佳的原因吗?可以通过关闭某些功能来解决这个问题吗?这是'性能测试:
//Two containers to be tested. 'Test' is a wrapper over decimal.
var arrayList = new C5.ArrayList<Test>();
var genericList = new System.Collections.Generic.List<Test>();
var toBeAdded = new List<Test>();
var watch = new Stopwatch();
//Fill both tested containers
for (int i = 10; i > 0; i--)
{
var test = new Test(i);
genericList.Add(test);
arrayList.Add(test);
}
//Fill the container the range of which will be inserted to the tested containers
for (int i = 5; i > 0; i--)
{
toBeAdded.Add(new Test(i+0.5m)); …Run Code Online (Sandbox Code Playgroud) c# ×2
arrays ×1
c5 ×1
collections ×1
containers ×1
dictionary ×1
optimization ×1
performance ×1