我应该关注 .NET 字典速度吗? [英] Should I be concerned about .NET dictionary speed?

查看:16
本文介绍了我应该关注 .NET 字典速度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将创建一个项目,该项目将大量使用字典查找和插入.这是需要担心的事情吗?

I will be creating a project that will use dictionary lookups and inserts quite a bit. Is this something to be concerned about?

另外,如果我做基准测试之类的而且真的很糟糕,那么用其他东西替换字典的最佳方法是什么?使用带有散列"键的数组会更快吗?但这对插入时间没有帮助吗?

Also, if I do benchmarking and such and it is really bad, then what is the best way of replacing dictionary with something else? Would using an array with "hashed" keys even be faster? That wouldn't help on insert time though will it?

此外,我不认为我在进行微优化,因为这确实将是生产服务器上代码的重要组成部分,所以如果这需要额外的 100 毫秒才能完成,那么我们将寻找新的方法来处理这个(事情.

Also, I don't think I'm micro-optimizing because this really will be a significant part of code on a production server, so if this takes an extra 100ms to complete, then we will be looking for new ways to handle this.

推荐答案

  1. 正在进行微优化.你还有工作代码吗?请记住,如果它不起作用,那么它不起作用都没有关系."(Mich Ravera) http://www.codingninja.co.uk/best-programmers-引号/.

  1. You are micro-optimizing. Do you even have working code yet? Remember, "If it doesn't work, it doesn't matter how fast it doesn't work." (Mich Ravera) http://www.codingninja.co.uk/best-programmers-quotes/.

您不知道瓶颈在哪里,而且您已经专注于字典.如果问题出在其他地方怎么办?

You have no idea where the bottlenecks will be, and already you're focused on Dictionary. What if the problem is somewhere else?

你怎么知道 Dictionary 类是如何实现的?也许它已经使用了一个带有散列键的数组!

How do you know how the Dictionary class is implemented? Maybe it already uses an array with hashed keys!

附言它实际上是.NET 词典",而不是C# 词典",因为 C# 只是使用 框架 的几种编程语言之一.

P.S. It's really ".NET Dictionaries", not "C# Dictionaries", because C# is just one of several programming languages that use the framework.

这篇关于我应该关注 .NET 字典速度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆