An introduction to Joblib

# Create a simple function which will be called multiple times in for loop
def square(x):
time.sleep(1) # Adding extra time to ensure we see the differencereturn x*x
start = datetime.now()for i in range(10):      print(square(i))end = datetime.now()print(f'Time taken: {end-start}')
# Calling the for loop, using 2 coresstart = datetime.now()def parallel_example(i):      return square(i)out = Parallel(n_jobs=2)(delayed(parallel_example)(i) for i in range(10))end = datetime.now()print(f'Time taken: {end-start}')
# Calling the for loop, using all the coresstart = datetime.now()def parallel_example(i):       return square(i)out = Parallel(n_jobs=10)(delayed(parallel_example)(i) for i in range(10))end = datetime.now()print(f'Time taken: {end-start}')

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store