pedrobaeza / python-progressbar

Automatically exported from code.google.com/p/python-progressbar
Other
0 stars 0 forks source link

Progressbar should update on a regular interval #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently the progressbar only updates 100 times, for large progressbars this 
is not nearly enough. I am currently using the script for a queue of about 2 
hours.

To fix this we could modify the _need_update method to change every second 
instead. This should do:

def _need_update(self):
    if self.seconds_elapsed:
        return int(self.seconds_elapsed) != int(time.time() - self.start_time)
    else:
        return True

Original issue reported on code.google.com by Wolphie on 1 Aug 2010 at 3:20

GoogleCodeExporter commented 9 years ago
I had actually thought about this issue. The only problem is incurring a call 
for time.time() in every step. I'll see if that can be avoided (maybe using an 
alarm, or a secondary thread), but it might even not be worth it.

Original comment by nilton.v...@gmail.com on 3 Aug 2010 at 5:13

GoogleCodeExporter commented 9 years ago
+1, maybe ETA can be used to determine number of updates required for smooth 
operation?

Original comment by kal...@gmail.com on 14 Dec 2010 at 3:14

GoogleCodeExporter commented 9 years ago
I'm not convinced that calling `time.time()` is a large problem

From IPython
In [1]: import time
In [2]: %timeit time.time()
1000000 loops, best of 3: 269 ns per loop

Original comment by Wolphie on 14 Dec 2010 at 3:28

GoogleCodeExporter commented 9 years ago
Interesting. It's a bit slower in the machine I'm using right now:

In [22]: %timeit pbar._need_update()
timeit1000000 loops, best of 3: 617 ns per loop

In [23]: %timeit time.time()
1000000 loops, best of 3: 1.37 µs per loop

Adding a call to time.time() in _need_update() increases the time of a single 
call to:

In [54]: %timeit pbar._need_update()
100000 loops, best of 3: 2.31 µs per loop

Original comment by nilton.v...@gmail.com on 14 Dec 2010 at 10:01

GoogleCodeExporter commented 9 years ago
Still doesn't look like a large enough amount to worry about. If you're 
actually running updates on the progress bar more than 432,900 times per second 
than you've got a different problem ;)

Original comment by Wolphie on 14 Dec 2010 at 10:08

GoogleCodeExporter commented 9 years ago
Done in 
https://code.google.com/p/python-progressbar/source/detail?r=a00c6b7ca3c5a1cd7c3
8386e91bffde086607e3d

Please check if it's OK, if you can. Thanks.

Original comment by nilton.v...@gmail.com on 15 Dec 2010 at 3:30

GoogleCodeExporter commented 9 years ago
It's working perfectly. Great patch!

Original comment by Wolphie on 16 Dec 2010 at 7:01