Author Topic: Really a difference with float, int, double  (Read 2813 times)

0 Members and 1 Guest are viewing this topic.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Really a difference with float, int, double
« 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?

Atook

  • Swamp Rat
  • Posts: 1027
  • AKA Tim
Re: Really a difference with float, int, double
« Reply #1 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.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2124
  • class keyThumper<T>:ILazy<T>
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2124
  • class keyThumper<T>:ILazy<T>
Re: Really a difference with float, int, double
« Reply #3 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/

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Really a difference with float, int, double
« Reply #4 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.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Really a difference with float, int, double
« Reply #5 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
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Really a difference with float, int, double
« Reply #6 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