如何慢是.NET异常? [英] How slow are .NET exceptions?

查看:183
本文介绍了如何慢是.NET异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想什么时候,而不是抛出异常的讨论。我想解决一个简单的问题。 99%的时间在他们身边,而被对方索赔慢不抛出异常的说法旋转(与基准测试),该速度不是问题。我读过许多博客,文章和帖子涉及一方或另一方。因此,这是什么呢?

I don't want a discussion about when to and not to throw exceptions. I wish to resolve a simple issue. 99% of the time the argument for not throwing exceptions revolves around them being slow while the other side claims (with benchmark test) that the speed is not the issue. I've read numerous blogs, articles, and posts pertaining one side or the other. So which is it?

在回答了一些链接:飞碟双向,的马里亚尼,的 Brumme

Some links from the answers: Skeet, Mariani, Brumme.

推荐答案

我在不慢的一面。我已经写了两articles 有关这一点。有基准方面的批评,其中大多下调至在现实生活中会更叠穿过去,所以你吹缓存等 - 但使用错误codeS,以您的方式工作的协议栈会的的打击缓存,所以我不认为这是一个特别好的说法。

I'm on the "not slow" side. I've written two short articles about this. There are criticisms of the benchmark aspect, which are mostly down to "in real life there'd be more stack to go through, so you'd blow the cache etc" - but using error codes to work your way up the stack would also blow the cache, so I don't see that as a particularly good argument.

只是要清楚 - 我不支持使用异常,他们是不符合逻辑。例如, int.TryParse 是完全适当的从用户的转换数据。阅读机器产生的文件,其中失败的意思是该文件不是在它的意思是格式时,这是合适的,我真的不希望尝试处理这个,因为我不知道还有什么可能是错误的。

Just to make it clear - I don't support using exceptions where they're not logical. For instance, int.TryParse is entirely appropriate for converting data from a user. It's appropriate when reading a machine-generated file, where failure means "The file isn't in the format it's meant to be, I really don't want to try to handle this as I don't know what else might be wrong."

在使用唯一合理的情况下,例外我从来没有见过其性能受例外是显著受损的应用程序。基本上,异常应该不会经常发生,除非你有显著正确性的问题,如果你有显著正确性问题则表现不是你所面临的最大的问题。

When using exceptions in "only reasonable circumstances" I've never seen an application whose performance was significantly impaired by exceptions. Basically, exceptions shouldn't happen often unless you've got significant correctness issues, and if you've got significant correctness issues then performance isn't the biggest problem you face.

这篇关于如何慢是.NET异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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