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 3314750
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:16:11+00:00 2026-05-17T22:16:11+00:00

Two Parts two my question. Which is more efficient/faster: int a,b,c,d,e,f; int a1,b1,c1,d1,e1,f1; int

  • 0

Two Parts two my question. Which is more efficient/faster:

int a,b,c,d,e,f;
int a1,b1,c1,d1,e1,f1;
int SumValue=0; // oops forgot zero
// ... define all values
SumValue=a*a1+b*b1+c*c1+d*d1+e*e1*f*f1;

or

Sumvalue+=a*a1+b*b1+c*c1;
Sumvalue+=d*d1+e*e1*f*f1;

I’m guessing the first one is. My second question is why.

I guess a third question is, at any point would it be necessary to break up an addition operation (besides compiler limitations on number of line continuations etc…).

Edit

Is the only time I would see a slow down when then entire arithmetic operation could not fit in the cache? I think this is impossible – compiler probably gets mad about two many line continuations before this could happen. Maybe I’ll have to play tomorrow and see.

  • 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-05-17T22:16:11+00:00Added an answer on May 17, 2026 at 10:16 pm

    Did you measure that? The optimized machine code for both approaches will probably be very similar, if not the same.

    EDIT: I just tested this, the results are what I expected:

    $ gcc -O2 -S math1.c  # your first approach
    $ gcc -O2 -S math2.c  # your second approach
    $ diff -u math1.s math2.s
    
    --- math1.s 2010-10-26 19:35:06.487021094 +0200
    +++ math2.s 2010-10-26 19:35:08.918020954 +0200
    @@ -1,4 +1,4 @@
    -   .file   "math1.c"
    +   .file   "math2.c"
        .section    .rodata.str1.1,"aMS",@progbits,1
     .LC0:
        .string "%d\n"
    

    That’s it. Identical machine code.

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

Sidebar

Related Questions

The question has two parts, one of which I already have the answer for.
This question has two parts. Part 1. Yesterday I had some code which would
Question I've built an app in two parts: a low-overhead server which listens for
My question has two parts: Is it possible that, if a segfault occurs after
This question has two parts (maybe one solution?): Sample vectors from a sparse matrix
This question is in two parts: A) Is my design wrong? If so, what
So, I'd like to know which of the following is more efficient. The best
Two Part Question: What kind of actions does SQL Server process in RAM? Of
Two part question... I've read in other posts that Apple's personal version of Java
So two part question here. Basically, what is the proper practise for javascript function

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.