Are doubles faster than floats in C#?

前端 未结 10 875
[愿得一人]
[愿得一人] 2020-12-02 20:06

I\'m writing an application which reads large arrays of floats and performs some simple operations with them. I\'m using floats, because I thought it\'d be faster than doubl

10条回答
  •  忘掉有多难
    2020-12-02 20:19

    I just read the "Microsoft .NET Framework-Application Development Foundation 2nd" for the MCTS exam 70-536 and there is a note on page 4 (chapter 1):

    NOTE Optimizing performance with built-in types
    The runtime optimizes the performance of 32-bit integer types (Int32 and UInt32), so use those types for counters and other frequently accessed integral variables. For floating-point operations, Double is the most efficient type because those operations are optimized by hardware.

    It's written by Tony Northrup. I don't know if he's an authority or not, but I would expect that the official book for the .NET exam should carry some weight. It is of course not a gaurantee. I just thought I'd add it to this discussion.

提交回复
热议问题