1 Replies - 556 Views - Last Post: 20 February 2013 - 03:08 PM Rate Topic: -----

#1 pathra  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-February 13

Using C++ operators effectively and efficiently

Posted 20 February 2013 - 02:26 PM

I'm trying to look into C++'s operators to see if it's possible to create a math function that executes faster than those in the STL, but less accurate, for when high precision isn't necessary (and also to expand my knowledge of some of the ones I haven't used as much, like the bitwise operators). A consideration, though, seems to be that not all operators are equal; I've heard that floating point multiplication can be very slow compared to bitwise operations.

Are there any other C++ operators that could possibly take a very long amount of time to execute, assuming that only int and float data types are used?

Also, does it take a long time to cast an int to a float and vice versa?

And, as a separate note, (for example) if there is a way to perform bitwise operations on floats, or other strange combinations, is it possible that it'll give a different result on a different machine than mine?

Is This A Good Question/Topic? 0
  • +

Replies To: Using C++ operators effectively and efficiently

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3452
  • View blog
  • Posts: 10,658
  • Joined: 05-May 12

Re: Using C++ operators effectively and efficiently

Posted 20 February 2013 - 03:08 PM

Good luck, if you are talking about replacing all these functions:
http://en.cppreferen...pp/numeric/math
http://en.cppreferen...numeric/complex
http://en.cppreferen.../numeric/random

then good luck. You've got a big project ahead of you. I'd like to see your performance numbers and too see if the weeks/months that you spend is worth the milliseconds of speed that you will gain.

As for getting different results on different machines, it's really a matter of several factors:
- raw speed of the processor
- processor architecture (ex. RISC vs CISC)
- processor family/generation with the family
- variants of the processor (same processor family, but different cache sizes)
- quality of your compiler
- quality of your runtime library

If you are willing to hold those factors stable to be able to do apples to apples comparison, then it should be the same results.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1