Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9179135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:43:21+00:00 2026-06-17T17:43:21+00:00

Version A : if ((A)&&(B)) doSth; if (B) doSthElse; Version B : if (B)

  • 0

Version A :

if ((A)&&(B)) doSth;
if (B) doSthElse;

Version B :

if (B)
{
    if (A) doSth;
    doSthElse;
}

Which of these two is preferable, performance-wise?

Notes :

  • The actual code will be used some millions of times per second, so performance and speed is crucial. Before proceeding to profiling, could you please give me some input in case I’m missing something?

  • The code is being compiled using Clang++ on Mac OS X 10.6.8, using -O3.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:43:22+00:00Added an answer on June 17, 2026 at 5:43 pm

    Assume A and B are both simple boolean values,
    We need take into account the likelihood of what the condition resolves into:

    1. short-cut evaluation: if (A) is likely to resolves to false than (B), write (A && B), otherwise (B && A).

    2. branch predictability: use conditions that more predictable enclose big blocks. for example, if B is predictable, then 2nd form is preferred.

    3. try to translate non-predictable conditional assignment into (? :), for example, prefer

      x = c ? a : b; // data dependency
      

      to

      if (c) x = a; // control flow dependency
      else   x = b;
      

    if c is not predictable.
    In this case, you want to substitute a control flow dependency by a data dependency, which can be compiled into a conditional move. It is net gain when the control dependency is not predictable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you have the following code: (ns foo) (defmacro defproject [project-name version & args]
I have this code (simplified version): const int& function( const int& param ) {
Short version: I have a Django project under development & testing (not yet into
Possible Duplicate: Best way to find Browser type & version? In HTML/JavaScript, How can
Version used: Delphi 7. I'm working on a program that does a simple for
Version 1.0 of an application has a data model, which is saved/loaded using the
I am trying to use jQuery (latest version) & ajax to poll a mysql
Is there a way I can change the basic text version of '&' and
I am trying to figure out the complete code as explained at: http://www.drdobbs.com/windows/microsofts-c-amp-unveiled/231600761?pgno=2 I
Consider this code: #include <iostream> #include <type_traits> using namespace std; template<typename T_orig> void f(T_orig&

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.