79575325

Date: 2025-04-15 13:54:23
Score: 1
Natty:
Report link

1/ Compare like with like

2/ use unit_scale to avoiding having to count every value on screen

3/ use chunksize to reduce map vs imap differences (credit @Richard Sheridan)

print("Running normaly...")
    t0 = time.time()
    with Pool(processes=cpu_count()) as pool:
        results = list(pool.imap(partial(dummy_task, size=size), steps, chunksize=size))
print("Running with tqdm...")
    t2 = time.time()
    with Pool(processes=cpu_count()) as pool:
        results = list(tqdm(pool.imap(partial(dummy_task, size=size), steps, chunksize=size), total=len(steps), unit_scale=True))

Running normaly...

Time taken: 2.151 seconds

Running with tqdm...

100%|███████████████████████████████████████████████████████████| 500k/500k [00:02<00:00, 237kit/s]

Time taken: 2.192 seconds

Pool Process with TQDM is 1.019 times slower.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Richard
  • Filler text (0.5): ███████████████████████████████████████████████████████████
  • Low reputation (0.5):
Posted by: Paul Smith