32/40
Part 7 of 7 · Follow-upsLearn and do

What interviewers ask next

These are the follow-ups the practice problem's README lists, plus two general ones.

Is it waiting on the disk or busy on the CPU?

Measure both clocks: time.perf_counter() for wall time, and time.process_time() for CPU time. Then compare them:

ClocksIt'sSo
wall ≈ CPUbusy on the CPUthreads: hashlib frees the GIL
wall ≫ CPUwaiting on the diskread less

Hashing the cached 256 MiB file took 0.133 s of wall time and 0.133 s of CPU. That's all CPU: SHA-256 at about 2 GB a second.

When it's busy on the CPU, threads help. The GIL is the lock that lets only one thread run Python at a time. hashlib releases it while it hashes more than 2047 bytes given in one call.

Predict

Hashing eight cached 64 MiB files on one thread took 0.268 s. About how long on 4 threads?

Pick an answer above to see the rest