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

  • Home
  • SEARCH
  • 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 8925091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:36:12+00:00 2026-06-15T07:36:12+00:00

int i = 3; Is there any performance difference between this code: if(i ==

  • 0

int i = 3;

Is there any performance difference between this code:

if(i == 2)
   DoA();
if(i == 3)
   DoB();
if(i == 4)
   DoC();

And this code:

if(i == 2)
   DoA();
else if(i == 3)
   DoB();
else if(i == 4)
   DoC();

I’m wondering if using optional ELSE affects how the CPU understands the code or not. I always think when we use the second approach, if i is 2 then the CPU does not check the other two conditions, but in the first approach although the first condition is true (i == 2) but the CPU does check the second and third conditions. Is this true?

  • 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-15T07:36:14+00:00Added an answer on June 15, 2026 at 7:36 am

    Of course it does affect — for better! It’s totally the opposite of unecessary, since by using those elses the compiler will skip the other if-checks and get better performance.

    But you shouldn’t be worring about it, the difference in performance in your example is so minimal it’s insignificant.

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

Sidebar

Related Questions

Is there any performance difference between using int a=a+1 and a++ in Java ?
Are there any performance difference between decimal(10,0) unsigned type and int(10) unsigned type?
I was wondering if there were any performance implications between using TPL TaskFactory.FromAsync and
Possible Duplicate: Is there any particular difference between intval and (int)? These two statements
Given the following code snippets, is there any appreciable difference? public boolean foo(int input)
Is there any performance difference between the for loops on a primitive array? Assume:
Is there any advantage of using int vs varbinary for storing bit masks in
Is there any reason why this shouldn't work? [PseudoCode] main() { for (int i
Is there any problem with my code ? std::vector<int[2]> weights; int weight[2] = {1,2};
In C#, would there be any difference in performance when comparing the following THREE

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.