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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:02:51+00:00 2026-05-25T21:02:51+00:00

My question is: How can I add features to my processing loop without the

  • 0

My question is: How can I add features to my processing loop without the overhead of checking the true/falseness of the user settings to navigate the branches? The settings are the same for all iterations on the loop. Do modern processors with branch prediction make this unnecessary?

My programs over follow this pattern:

  1. User adjusts settings, checkboxes, sliders, numerical entries.
  2. Data is processed when an update is triggered
    1. Apply settings to local variables
    2. Run loop over a large dataset
      • add if statements to bypass unused code from the user settings.
      • return from loop
    3. return transformed data

How can you template or inline out all permutations ahead of time?

example:

bool setting1 = true;
bool setting2 = false;
vector<float> data;

for(int i=0;i<100000;i++)
    data.push_back(i);

for(int i=0;i<100000;i++) {
    if (setting1)
    {
       doStuff(data[i]);
       ....
    }
    if (setting2)
    {
       doMoreStuff(data[i]);
       .....
    }

    .... //etc
}

I know this is a silly example. But I’d like to know what pattern scales when there are lots of branches.

  • 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-25T21:02:52+00:00Added an answer on May 25, 2026 at 9:02 pm

    Use templates for the main loop.

    template <bool A, bool B>
    void loop() {
      while (1) {
          if (A) // will get compiled out if A == false
          {
             doStuff(data[i]);
             ....
          }
          if (B)
          {
             doMoreStuff(data[i]);
             .....
          }
    
          .... //etc
      }
    }
    

    When you change settings: (you could probably make this less code)

    if (setting1) {
      if (setting2)
        loop<1,1>;
      else 
        loop<1,0>;
    }
    else {
      if (setting2)
        loop<0,1>;
      else 
        loop<0,0>;
    }
    

    You want to stay in loop() until settings change.

    This should be used with care as it can lead to bloat.


    Profiled the answers (G++ O2 optimization):

     %Time
     46.15      0.84     0.84                             fb() (blackbear)
     38.37      1.53     0.69                             fa() (OP)
     16.13      1.82     0.29                             fc() (pubby8)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now I can add single value or tubles to the pipeline, my next question
When I'm asking this question on stackoverflow, I can add tags to it. So,
My question is simple. Can I add either of the blow :prompt => Any
My question is somewhat weird, but can i add events for any DOM elements(div),
I have question regarding the SQLAlchemy. How can I add into my mapped class
The question pretty much already says everything. I'm starting to add some features to
Question Can I build a image database/library that has an e-commerce style checkout system
Simple question: Can a swing frame be completely modal ( block all others windows
Simple question: Can I mix in my desktop application Java and JavaFX Script code?
this question can create a misunderstanding: I know I have to use CSS to

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.