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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:43:54+00:00 2026-06-13T08:43:54+00:00

I am working on some grid generation code, during which I really want to

  • 0

I am working on some grid generation code, during which I really want to see where I am, so I download a piece of progress bar code from internet and then inserted it into my code, something like:

std::string bar;

for(int i = 0; i < 50; i++)
{
    if( i < (percent/2))
    {
        bar.replace(i,1,"=");
    }
    else if( i == (percent/2))
    {
        bar.replace(i,1,">");
    }
    else
    {
        bar.replace(i,1," ");
    }
}

std::cout<< "\r" "[" << bar << "] ";
std::cout.width( 3 );
std::cout<< percent << "%     "
    << " ieration: " << iterationCycle << std::flush;

This is very straightforward. However, it GREATLY slows down the whole process, note percent=iterI/nIter.

I am really get annoyed with this, I am wondering if there is any smarter and more efficient way to print a progress bar to the screen.

Thanks a million.

  • 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-13T08:43:55+00:00Added an answer on June 13, 2026 at 8:43 am

    Firstly you could consider only updating it on every 100 or 1000 iterations. Secondly, I don’t think the division is the bottleneck, but much rather the string operations and the outputting itself.

    I guess the only significant improvement would be to just output less often.

    Oh and just for good measure – an efficient way to only execute the code every, say, 1024 iterations, would be not to see if 1024 is a divisor using the modulo operations, but rather using bitwise calls. Something along the lines of

    if (iterationCycle & 1024) {
    

    would work. You’d be computing the bitwise AND of iterationCycle and 1024, only returning positive for every time the bit on the 10th position would be a 1. These kind of operations are done extremely fast, as your CPU has specific hardware for them.

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

Sidebar

Related Questions

I want to display some text below each grid image. Please see my code
I am working on a grid which displays number of records,based on some filters.I
I have a code which is working fine and displaying some set of values
I'm working on a c# wpf app in which I want a grid or
I am working on telerik grid in NopCommerce with some customization. I want to
I'm working some code that inserts csv rows into an SQLite database using Python.
I've been re-working some code due to a memory leak. The code is part
Working on some tweaks for a build script, I noticed that the output from
Working on some code for a machine problem; we've just started working with pointers,
After working on some test code for open ID authentication, I had a break

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.