verigak / progress

Easy to use progress bars for Python
ISC License
1.41k stars 179 forks source link

next function taking an optional value of steps #94

Open delbertaud opened 3 years ago

delbertaud commented 3 years ago

I've noticed while processing a large run (number of iterations) that refreshing the progress bar with a bar.next() on each causes a delay. It might be of value to add an optional incoming attribute of the next function that would just the bar forward x steps without refreshing the bar on each step. Example if I'm iterating over 1,000,000 items in a list but only wish to refresh the progress bar every 1,000 making a bar.next(1000) would be efficient.

delbertaud commented 3 years ago

Sorry this is a case of not reading the code. I have found bar.goto(1000) solves this issue.

MarkCBell commented 3 years ago

bar.next() does take an optional argument n which defaults to 1 and specifies the amount to increment the bar's index by (https://github.com/verigak/progress/blob/master/progress/__init__.py#L123).

So you can do:

with progress.bar.Bar('Progress', max=10**6) as bar:
    for i in range(10**6):
        if i % 100 == 0: bar.next(100)
        # Do some calculation with i