exception - CLR 与 OCaml 异常开销

标签 exception f# clr ocaml

阅读开始 F# - Robert Pickering 我专注于以下段落:

Programmers coming from an OCaml background should be careful when using exceptions in F#. Because of the architecture of the CLR, throwing an exception is pretty expensive—quite a bit more expensive than in OCaml. If you throw a lot of exceptions, profile your code carefully to decide whether the performance costs are worth it. If the costs are too high, revise the code appropriately.



为什么,由于 CLR,如果 F# 抛出异常会更昂贵比 OCaml ?在这种情况下,适当修改代码的最佳方法是什么?

最佳答案

CLR 中的异常非常丰富,并且提供了很多细节。 Rico Mariani 在 the cost of exceptions 上发布了一个(旧的,但仍然相关的)帖子。在 CLR 中详细介绍了其中的一些内容。

因此,在 CLR 中引发异常比在其他一些环境(包括 OCaml)中具有更高的相对成本。

And what is the best way to revise the code appropriately in this case?



如果您希望在正常、非异常情况下引发异常,您可以重新考虑您的算法和 API,以完全避免异常。例如,尝试提供一个替代 API,您可以在其中测试环境,然后再引发异常。

关于exception - CLR 与 OCaml 异常开销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10964851/

相关文章:

.net - 请澄清我对对象和引用以及值类型的理解是当前的?

php - 如何在接口(interface)文档中记录@throws

javascript - 从 Express 路由引发异常时,未调用未处理的异常事件处理程序

objective-c - main 方法中抛出的 Objective C 异常

compilation - f# - 使用通用对象而不将其传递到任何地方

f# - 如何检查函数的类型参数是否静态解析?

orm - F# 类型提供程序是否会为实现对象关系映射提供良好的基础?

c++ - 1>链接: fatal error LNK1104: cannot open file 'MSCOREE.lib' `

.net - .NET CLR 何时评估安全属性?

java - Eclipse:在 block 中查找可以抛出异常的行