in reply to Using a progress bar... having issues

I couldn't get Term::ProgressBar to work

Take a look at this node Term::ProgressBar or try this

#! /usr/bin/perl use strict; use Term::ProgressBar; my $low = 1; my $high = 20; my $status = Term::ProgressBar->new( { name => 'Progress', count => $high - $low + 1, term_width => 80, }); my $count = 0; for my $no ( $low .. $high ){ # # calc prime # sleep 1; $status->update(++$count); }
poj

Replies are listed 'Best First'.
Re^2: Using a progress bar... having issues
by james28909 (Deacon) on Aug 09, 2015 at 03:21 UTC
    Not trying to hi-jack the thread, I just slapped this code of yours a modified version of this code above into a byte reverse script I have, and it does work correctly, but it slows it down dramatically. I guess it is all the figuring of the percentages and printing to console. In my tests with Time::HiRes I get times of .02 sec without printing progress bar, and times of .78 sec with progress bar. Any ideas to speed that up? Sorry if I am getting off topic, I just didnt want to make a new thread.

    EDIT: I was able to speed it up to .22 sec with progress bar by adjusting the buffer size.
    EDIT2: Nevermind, I got it back to =~ .1 sec. Though I would like to get it back down to around .02 :P

      For anything taking less than about a second a progress bar is, as you have amply demonstrated, a complete waste of time. As a general thing aim for a progress bar update about every 1/10th of a second. That means having some idea of how long each iteration of your process takes an perform a progress bar update every 1 / (10 * iteration seconds) iterations.

      Premature optimization is the root of all job security
        Yes, I know it is a complete waste of time haha. I didnt want to hijack the thread and just wanted to ask about it. If it were a larger file that took a while to process, then it would have a significant difference. I was just wondering if it was because the calculations for the percentage, or printing the actual progress bar, or a combination of both? But it was the size of the buffer that was slowing it down tremendously. Now it transitions alot quicker, especially with larger files. This was the first time i ever attempted using a progress bar as well. Im not a professional by far and never claim to be. Im just an enthusiast programmer and like tinkering. And thanks for the wisdom as well. I will keep that in mind next time i /must/ have a progress bar.

        Cheers :)