29
loading...
This website collects cookies to deliver better user experience
tqdm
for a long time may it be for fun side projects or production code.tqdm
to implement it.from time import time
from tqdm import tqdm
LOOP = 50000
def task(update_cycle):
pbar = tqdm(total=LOOP)
for i, _ in enumerate(range(LOOP)):
for _ in range(LOOP):
pass
if i % update_cycle == 0:
pbar.update(update_cycle)
pbar.close()
tic = time()
print(f'Update cycle: {1}')
task(1)
toc = time()
print(f'Time elapsed: {toc-tic:0.2f} seconds\n')
tic = time()
print(f'Update cycle: {500}')
task(500)
toc = time()
print(f'Time elapsed: {toc-tic:0.2f} seconds')
tqdm
is a fantastic package to implement progress bars. We can get a usable progress bar with just a single line of code and also it gives a wide range of customization. But next time when you implement a progress bar just make sure that it does not affect the performance.