F# and C# 's CLR is same then why is F# faster than C#

前端 未结 7 836
失恋的感觉
失恋的感觉 2021-01-18 02:42

I am confused and would appreciate if you enlighten me. F# uses same CLR as C# and underlying code is identical then how can one suggest that a function runs faster when wr

7条回答
  •  醉酒成梦
    2021-01-18 02:57

    There could be any number of reasons for code written in one language to be faster than code written in the other, even if they use the same runtime library. However, the .NET runtime library isn't the only runtime library involved. As I understand it, there is a rather large F# runtime library that does things that are F#-specific. The F# compiler knows about that library. The C# compiler doesn't. So the F# compiler can make calls to highly optimized runtime library code that the C# compiler doesn't have access to.

    If they're both using the same set of runtime libraries, then I would expect the programs to be close to the same, but not exact. The individual compilers could generate more or less optimum code for particular constructs.

提交回复
热议问题