Float or Double?

前端 未结 8 1926
北海茫月
北海茫月 2020-12-29 20:36

Which is faster, double or float, when preforming arithimic (+-*/%), and is it worth just using float for memory reasons? Precision is not an issue much of an issue.

8条回答
  •  轮回少年
    2020-12-29 21:40

    In speed terms, there's no difference between float and double on the more modern hardware.

    Very cheap devices seem to have a limited FPU where float is faster than double. I tested on a CMX device that is currently marketed as one of the the cheapest tablets in the world:

    • "float" test code takes 4.7 seconds
    • same code with "double" takes 6.6 seconds

    This question has been asked a couple of times ...

    Yes. Because the answer differs for different types of hardware. On desktop computers double has the same speed as float. On devices without FPU (interesting for WLAN router hacks) float is 2-5 times faster than double; and on devices with 32-bit FPU (often found in industrial and automotive applications) even up to 100 times.

    Please check out this article ...

    The last section of the article says that you have to do time measurements on the hardware device you are going to use to be 100% sure.

提交回复
热议问题