在为C#程序编写数学函数时,F#能否表现良好?

在为C#程序编写数学函数时,F#能否表现良好?,第1张

概述与C#相比,有没有人知道F#在性能方面的衡量标准.我有一个带有大量矢量 *** 作,光线碰撞算法等的C#光线跟踪器,并认为它们可能更容易用F#表示.我不是要问F#在表达数学问题上的表现有多好,这已经回答了 here,而是我应该期待更好或更差的表现?由于光线跟踪是非常高性能的,即使是性能不佳的小案例也可能是错误的地方. 编辑: 似乎已经有很多关于这个问题的问题我找不到了(如果你真的用“F#”这个词搜索任何东 与C#相比,有没有人知道F#在性能方面的衡量标准.我有一个带有大量矢量 *** 作,光线碰撞算法等的C#光线跟踪器,并认为它们可能更容易用F#表示.我不是要问F#在表达数学问题上的表现有多好,这已经回答了 here,而是我应该期待更好或更差的表现?由于光线跟踪是非常高性能的,即使是性能不佳的小案例也可能是错误的地方.

编辑:

似乎已经有很多关于这个问题的问题我找不到了(如果你真的用“F#”这个词搜索任何东西都没有结果). here的一个好处是以下答案:

F# provIDes some performance-related
features that can make a difference.

Firstly,the implementation of
delegates on .NET is currently quite
inefficIEnt and,consequently,F# uses
its own FastFunc type for
high-performance first-class
functions.

Secondly,F# uses .NET Metadata to
convey inline functions so that they
can be exported across APIs and,of
course,that can dramatically improve
performance in certain circumstances.

Finally,pattern matching can be
extremely laborIoUs to express in C#
because the language lacks pattern
matching but it is almost impossible
to maintain optimized C# code
equivalent to many non-trivial pattern
matches. In contrast,the F# compiler
aggressively optimizes pattern matches
during compilation.

Conversely,the C# compiler is better
at optimizing loops using IEnumerables
and is better at optimizing
computations over value types (e.g.
complex arithmetic).

Cheers,Jon Harrop.

解决方法 是的,F#表现更好.

以下是使用不同语言实现的单线程算法的一些性能结果(基准激活函数方法用于神经网络):

C#:

10^7 iterations using SigmoID1() took 3899,1979 ms10^7 iterations using SigmoID2() took 411,4441 ms

纯C:

10^7 iterations using sigmoID1: 628 ms10^7 iterations using sigmoID2: 157 ms

F#:

10^7 iterations using sigmoID1: 588.843700 ms10^7 iterations using sigmoID2: 156.626700 ms

More details

总结

以上是内存溢出为你收集整理的在为C#程序编写数学函数时,F#能否表现良好?全部内容,希望文章能够帮你解决在为C#程序编写数学函数时,F#能否表现良好?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1244654.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存