TheSwamp

Code Red => .NET => Topic started by: hobleglobsquishyworms on July 12, 2019, 11:23:31 PM

Title: Really a difference with float, int, double
Post by: hobleglobsquishyworms on July 12, 2019, 11:23:31 PM
Is there much of a difference in speed for most applications between using float, int, double, etc anymore with the power of computers?  I imagine to notice it someone would have to develop some incredible program.  Am I wrong?
Title: Re: Really a difference with float, int, double
Post by: Atook on July 13, 2019, 12:58:41 AM
I'm curious about performance too.

But really, from an interfacing with CAD perspective, it's best just to feed CAD the type it's expecting.
Title: Re: Really a difference with float, int, double
Post by: kdub on July 13, 2019, 01:23:40 AM


https://lmgtfy.com/?q=speed%20difference%20with%20float%2C%20int%2C%20double%2C%20decimal%20%20in%20C%23&s=g
Title: Re: Really a difference with float, int, double
Post by: kdub on July 13, 2019, 02:00:37 AM
... and this will probably be enough to give you bloodshot eyes.

http://nicolas.limare.net/pro/notes/2014/12/12_arit_speed/

Title: Re: Really a difference with float, int, double
Post by: dgorsman on July 15, 2019, 04:20:23 AM
What scale are you looking at?  Hundreds to thousands, probably no difference visible to the user.  Hundreds of thousands to millions,  larger value types will start to show a difference.  Still, bad idea to get too complacent.  No need to be uber optimized everywhere, but being aware makes for better, more efficient code overall.
Title: Re: Really a difference with float, int, double
Post by: MickD on July 15, 2019, 06:55:37 PM

I don't know how much the C# compiler optimises memory for class variables but in C/C++ it can be important to 'byte align' your variables to make them easier to access in 32/64 bit lumps but that is probably less important than how you structure your routines and bulk data (cache misses can have a ~200X speed factor hit on cpu performance!). That is, it is more efficient to grab your functions and variables and hope they fit in the cache (say L1/L2) and then run them as much as you can before retrieving the next lot of code and data.
So yes, it _can_ be important if you are coding for embedded systems or VR/Games/Animation.

Given that, unless you are trying to perform gig's of calculations at 60 frames per second then it's not worth worrying about, even if it was slower using doubles over floats we're talking milliseconds 'difference' per run of routine. If this is really important then I wouldn't be using any language that's interpreted or that runs on a VM like C#.

hth
Title: Re: Really a difference with float, int, double
Post by: It's Alive! on July 16, 2019, 06:32:48 AM
Yes, they can make a huge difference if you're using SIMD, google SIMD-enabled types for .NET

SSE2 XMM registers:
    four 32-bit single-precision floating point numbers
    two 64-bit double-precision floating point numbers or
    two 64-bit integers or
    four 32-bit integers or
    eight 16-bit short integers or
    sixteen 8-bit bytes or characters.

Otherwise probably not, just use the type that you need