go execution speed for float64 based calculations vs float32

2,148 views
Skip to first unread message

lgo...@gmail.com

unread,
Apr 21, 2019, 9:55:58 PM4/21/19
to golang-nuts
?? On 64-bit CPUs does anyone have any experience comparing the run-time speed of float64 based calculations vs float32 ?

Some of my C-code when translated to Go-code seems to run noticeably slower, so I'm wondering if I can speed things up by converting float vars to float32 vs float64 

Robert Engels

unread,
Apr 21, 2019, 10:09:09 PM4/21/19
to lgo...@gmail.com, golang-nuts
At least on intel, float64 should be faster than float32 since all math is done on the fpu in 64 bits, so it needs to be converted, but the memory bus also comes into play. 

I would doubt it. Float32 is designed for size not performance. 

On Apr 21, 2019, at 8:55 PM, lgo...@gmail.com wrote:

?? On 64-bit CPUs does anyone have any experience comparing the run-time speed of float64 based calculations vs float32 ?

Some of my C-code when translated to Go-code seems to run noticeably slower, so I'm wondering if I can speed things up by converting float vars to float32 vs float64 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

lgo...@gmail.com

unread,
Apr 22, 2019, 1:57:27 AM4/22/19
to golang-nuts
I note that this issue has been dealt with in a previous post  https://groups.google.com/forum/#!topic/golang-nuts/n12khle-mlY
The gist of which seems to suggest that 32-bit is faster than 64


On Sunday, April 21, 2019 at 10:09:09 PM UTC-4, Robert Engels wrote:
At least on intel, float64 should be faster than float32 since all math is done on the fpu in 64 bits, so it needs to be converted, but the memory bus also comes into play. 

I would doubt it. Float32 is designed for size not performance. 

On Apr 21, 2019, at 8:55 PM, lgo...@gmail.com wrote:

?? On 64-bit CPUs does anyone have any experience comparing the run-time speed of float64 based calculations vs float32 ?

Some of my C-code when translated to Go-code seems to run noticeably slower, so I'm wondering if I can speed things up by converting float vars to float32 vs float64 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com.

Robert Engels

unread,
Apr 22, 2019, 8:18:37 AM4/22/19
to lgo...@gmail.com, golang-nuts
The email you cite is for integers. Integer math is not performed by the fpu - so it is not the same. 
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

Marvin Renich

unread,
Apr 22, 2019, 8:49:07 AM4/22/19
to golang-nuts
* lgo...@gmail.com <lgo...@gmail.com> [190422 01:57]:
> I note that this issue has been dealt with in a previous post
> https://groups.google.com/forum/#!topic/golang-nuts/n12khle-mlY
> The gist of which seems to suggest that 32-bit is faster than 64

That thread was specific to integer remainder (%) and is irrelevant to
any other integer operation and completely irrelevant to floating point.
There was also no mention of architecture, which will also influence the
result.

On the amd64 architecture, the FPU operates internally on 10-byte
floating point values, and there is a conversion when loading and
storing both 4-byte and 8-byte floats.

If performance is important in the part of your app that is doing
floating point manipulation, profile your app. Write that part of the
app so that you can easily change between float32 and float64, and
profile both cases.

Micro benchmarks can give you some ideas, but for real answers, you need
to test in situ.

...Marvin

Marvin Renich

unread,
Apr 22, 2019, 8:55:17 AM4/22/19
to golang-nuts
* lgo...@gmail.com <lgo...@gmail.com> [190421 21:56]:
I would be more suspicious of the C-to-Go conversion than float32 vs
float64. While Go has similarities to C, rewriting in Go with its
strengths and weaknesses in mind will produce much better code all
around (performance and maintainability).

...Marvin

L Godioleskky

unread,
Apr 22, 2019, 11:28:34 AM4/22/19
to golang-nuts
Thanks guys for the cogent clarifications..I will now forget  about converting to float32 on 64-bit CPUs
 
I'm in the process of converting my often-used C-code apps to Go because I see tremendous advantages of Go vs C. 

I've been using C,C++ for many years and only recently discovered Go...
My Go knowledge is 100% self-taught and entirely based on Go web docs, tutorials, blogs etc
A good doc on "C  to Go code conversion",would help me greatly, so if  anyone knows of one, I'd appreciate knowing about it 
I'm somewhat reluctant to use software based conversion

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/3Io9xRmqAWM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages