I want to create two lists by running two functions (returning a value each for every run) in parallel. My code below works, but is still taking too much time. Is there a more efficient way to parallelize this code?
import time
from joblib import Parallel, delayed
catchments = 50 #define number of catchments to plot here
randomlist = random.sample(range(2, 2100), catchments)
def budx(i): #Time-taking task....
try:
catch = slicecatch(i)
return catch.PETNatVeg.mean().values/catch.Prec.mean().values
except IndexError as e:
pass
def budy(i): #Time-taking task....
try:
catch = slicecatch(i)
return catch.TotalET.mean().values/catch.Prec.mean().values
except IndexError as e:
pass
start_time = time.perf_counter()
bud_x = Parallel(n_jobs=-1)(delayed(budx)(i) for i in randomlist)
bud_y = Parallel(n_jobs=-1)(delayed(budy)(i) for i in randomlist)
finish_time = time.perf_counter()