Are doubles faster than floats in C#?

前端 未结 10 862
[愿得一人]
[愿得一人] 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:20

    Matthijs,

    You are wrong. 32-bit is far more efficient than 16-bit - in modern processors... Perhaps not memory-wise, but in effectiveness 32-bit is the way to go.

    You really should update your professor to something more "up-to-date". ;)

    Anyway, to answer the question; float and double has exactly the same performance, at least on my Intel i7 870 (as in theory).

    Here are my measurements:

    (I made an "algorithm" that I repeated for 10,000,000 times, and then repeated that for 300 times, and out of that I made a average.)

    double
    -----------------------------
    1 core  = 990 ms
    4 cores = 340 ms
    6 cores = 282 ms
    8 cores = 250 ms
    
    float
    -----------------------------
    1 core  = 992 ms
    4 cores = 340 ms
    6 cores = 282 ms
    8 cores = 250 ms
    

提交回复
热议问题