Jump to content

Bitwise operators


Guest terraego

Recommended Posts

Hey, this is my first post!

i was reading through some mangos source code and i'm really interested in how this emulator works. im quite new to c++ but i cant help but notice that people dont use bitwise operators. like so:

if (a&b) 
   {
    action
   }

instead of

if (a&&b) 
   {
    action
   }

now bitwise operators are faster. if 'a' is false it automaticly stops processing and return 0, it doesnt check the other variable. so i was interested and did some tests. this is what came out:

**********************************
bitwise [00]: 2235 nanoseconds result: false  
bitwise [10]: 1676 nanoseconds result: false  
bitwise [01]: 2235 nanoseconds result: false  
bitwise [11]: 1676 nanoseconds result: true  
**********************************
non bitwise [00]: 2793 nanoseconds result: false  
non bitwise [10]: 1955 nanoseconds result: false  
non bitwise [01]: 1955 nanoseconds result: false  
non bitwise [11]: 1677 nanoseconds result: true  
**********************************

as you can see, using bitwise operators is at least 10% faster then not using bitwise operators. for the testing i used:

        if (a && b) {
           result = true;
       } else {
           result = false;
       }

the using of bitwise operators seems faster when using while, will this help you guys in any way?

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use