• Advertisement
Sign in to follow this  

How Much speed the usage of Bitwise operations bring ?

This topic is 4962 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

As we know with Bitwise operators we can make some opearations as a) multiplyin 2 or dividing by 2 b) swipping two variable values without a need of a third one c) changin some part of a Variable that hold many knowledges (for ex: taking the RED bytes from a COLORREF) all i am curious is How much Speed does Usage or bitwise operations bring?is it significant or unimportant?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by tonymontana
As we know with Bitwise operators we can make some opearations as
a) multiplyin 2 or dividing by 2
b) swipping two variable values without a need of a third one
c) changin some part of a Variable that hold many knowledges
(for ex: taking the RED bytes from a COLORREF)

all i am curious is How much Speed does Usage or bitwise operations bring?is it significant or unimportant?


  • Very little. Your compiler will generally optimize such situations better than you can. Performance gains will be better made by profiling first, then adjusting your algorithms, and finally focusing on more specific optimizations, like such tiny things as bitwise operations.

  • Change your signature.

Share this post


Link to post
Share on other sites
Holy crap! is that your sig?

Anyway, in terms of performance, bitwise operators are as cheap as you can get. Most (maybe all) bitwise operations can be done in a single processor step.

Share this post


Link to post
Share on other sites
Your signature is so long as to be annoying. Instead of putting the whole thing in your signature, provide a link to it.

Share this post


Link to post
Share on other sites
I suppose it depends on what you substitute with bitwise operators. Working on a software renderer I found a huge performance increase when switching from floating point to fixed point, using left and right shift to multiply, devide and otherwise manipulate decimal numbers and store them as integers.

On the subject of your sig, change it please. This isnt an attack on the content of your sig, rather the size of it.

Share this post


Link to post
Share on other sites
Definetly agree with Washu.
Quote:
a) multiplyin 2 or dividing by 2

If you look at the actual code that your compiler produces, you'll notice that (if its a decent compiler) almost all int*2 or int/2 will be substituted with a bit-shift because the compiler is trying to optimize your code. Also, trying to bitshift a floating point types will produce unwanted results, so if you need to be accurate to some decimal places, then you'll need to multiply/divide anyways.
Quote:
b) swipping two variable values without a need of a third one

Unless you really need to save any extra memory you can, this isn't going to make any noticeable difference.
Being in the "for Beginners" section, I assume you've heard that bitwise operators are faster from books, which also mention the interger math is much faster than floating point. However, I believe that Pentium 4 and considerable level processors perform floating point math as fast or faster than interger math, so many of these optimizations are really not gaining you any time at all. Like Washu mentioned, the best idea is to profile your code and target the slowest sections. Optimizing a single algorithm can give you a huge performance boost if you were just coding it to make it work at first.
----------------------------------------------------------
I won't comment on the signature because I think enough has been said

Share this post


Link to post
Share on other sites
Quote:
Original post by tonymontana
no
because i am a free-man i will not change it
and because you are a moderator.ý have to say that iwill not post it much but i liked it.
any disagreement?
I can simply flip a bit in your profile and make it impossible for you to use a signature at all. If you don't change your signature volutarily, I'll do exactly that.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement