I added a progress bar to my 2.7 python code using tqdm but it has slowed down my code significantly. Without the progress bar for one example it takes 12 seconds while with the progress bar it takes 57 seconds.
The code without the progress bar looks like this:
p = mp.Pool()
combs = various combinations
result = p.map(self.parallelize, combs)
p.close()
p.join()
The code with the progress bar is as follows:
from tqdm import tqdm
p = mp.Pool()
combs = various combinations
result = list(tqdm(p.imap(self.parallelize, combs), total = 5000))
p.close()
p.join()
Is there a better way that wouldn't slow down my code as much?
Here is the console working with tqdm. As you see here the program has slowed down by almost factor of ten. A request of 100 points takes normally 00.297000 seconds.
tqdm is a library in Python which is used for creating Progress Meters or Progress Bars. tqdm got its name from the Arabic name taqaddum which means 'progress'. Implementing tqdm can be done effortlessly in our loops, functions or even Pandas.
tqdm(range(0, 30)) ) does not work with multiprocessing (as formulated in the code below). The progress bar is displayed from 0 to 100% (when python reads the code?) but it does not indicate the actual progress of the map function. How can one display a progress bar that indicates at which step the 'map' function is ?
tqdm is the default iterator. It takes an iterator object as argument and displays a progress bar as it iterates over it. You can see the nice output with 9.90it/s meaning an average speed of 9.90 iterations per second.
Can it be related to the usage of map
and imap
rather than twdm? See this great answer from the community. multiprocessing.Pool: What's the difference between map_async and imap?
Plus, you can adjust the update frequency of tqdm with the ministers
parameter. If it is really related to tqdm reducing the update frequency might solve your problem.
miniters : int or float, optional Minimum progress display update interval, in iterations. If 0 and dynamic_miniters, will automatically adjust to equal mininterval (more CPU efficient, good for tight loops). If > 0, will skip display of specified number of iterations. Tweak this and mininterval to get very efficient loops. If your progress is erratic with both fast and slow iterations (network, skipping items, etc) you should set miniters=1.
https://github.com/tqdm/tqdm#usage
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With