Archived

This topic is now archived and is closed to further replies.

level10boy

Performance Question

Recommended Posts

Can anyone tell what is faster, bitwise comparisons or logical comparaisons. For example is, which of the following is faster? 1. int a = 5; int b = 5; if ( a && b ) cout << "equal"; 2. int a = 10; if ( a & 0x0000000A ) cout << "equal"; Thanks for any answers.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Be careful, example 1 doesn''t do what you think it does. Here are some examples to demonstrate this.

#1
  
int a = 5;
int b = 10;

if (a && b)
cout << "equal"; // will execute



#2
  
int a = 0;
int b = 0;

if (a && b)
cout << "equal"; // will never execute


Share this post


Link to post
Share on other sites
Optimizations on this level save you at most a few CPU ticks (i.e. a few nanoseconds on today''s PCs), so it really doesn''t matter unless you perform the operation literally tens of million times per second.

Optimization in games today are about better scene graph management - things like BSP trees perform well no matter how slowly they''re implemented because they save orders of magnitude more time than they take to execute.

Share this post


Link to post
Share on other sites
quote:
Original post by level10boy
Can anyone tell what is faster, bitwise comparisons or logical comparaisons. For example is, which of the following is faster?

As the Anonymous Poster mentioned, your first example isn't a bitwise comparison but a logical one (with a slightly different set of rules). Here's an even better example:

int a = 5;
int b = 2;
if(a && b)
cout << "equal" endl; // will execute

Guess why?

Edit: formatting.

Edited by - Oluseyi on October 23, 2001 2:54:23 AM

Share this post


Link to post
Share on other sites