编辑:
似乎已经有很多关于这个问题的问题我找不到了(如果你真的用“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.
解决方法
以下是使用不同语言实现的单线程算法的一些性能结果(基准激活函数方法用于神经网络):
C#:
10^7 iterations using Sigmoid1() took 3899,1979 ms 10^7 iterations using Sigmoid2() took 411,4441 ms
纯C:
10^7 iterations using sigmoid1: 628 ms 10^7 iterations using sigmoid2: 157 ms
F#:
10^7 iterations using sigmoid1: 588.843700 ms 10^7 iterations using sigmoid2: 156.626700 ms