#### Archived

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

# Performance Question

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

## 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 on other sites
neither

seeing as at compile time it''ll get converted too..

if ( a & 0x0000000A )

why goto the hassle

##### Share on other sites
Assuming that you know they both don''t do the same thing, #2 will be faster a higher percentage of the time (in general). Sometimes they''ll be equal in speed, however.

[Resist Windows XP''s Invasive Production Activation Technology!]

##### Share on other sites
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 on other sites
Thanks for all your replies, and I''ll take it all into consideration.

##### 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 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

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 47
• ### Forum Statistics

• Total Topics
632636
• Total Posts
3007574
• ### Who's Online (See full list)

There are no registered users currently online

×