Skip to content

Instantly share code, notes, and snippets.

View zhenyuan992's full-sized avatar

zhen yuan zhenyuan992

View GitHub Profile
@zhenyuan992
zhenyuan992 / benchmark_python_multiprocessing.py
Last active December 5, 2022 06:55
benchmarks python's build-in multiprocessing. uses all the threads available in the system.
import multiprocessing as mp
import timeit
threads=mp.cpu_count()
print(f"Number of threads: {threads}")
vlist=range(15000) # takes about 5 seconds to run serially
def f(v):
return sum([v_ for v_ in range(v)])
start_pool = timeit.default_timer()
with mp.Pool(threads) as p: