I have a curious case. Unfortunately, I did not manage to reproduce the computation times in the MWE below but my project is basically a more crowded version. I wanted to speedup my code so I tried out differential_evolution with worker=-1. This did not work because of pickling issues (AttributeError: Can't pickle local object); I don't really want to define my cost-function at the top level of my module. So I used worker=Pool(ncpu).map instead. In my local MWE this works, but when migrating this change to my project I observe the following. I observe that using two different approaches I find that differential_evolution takes more then 10 times as much time to finish in the second (class-based) approach then the first approach. When I look into my CPU load for approach 1 I see that all cores are used. However in approach 2 basically only one core is being used. When I look at the output via disp=True I also see that the func evaluations are printed way slower as well in the 2nd approach compared to the 1st. Any idea what that might be? Tx. from os import cpu_count from time import time import numpy as np from pathos.multiprocessing import ProcessingPool as Pool from scipy.optimize import differential_evolution from scipy.integrate import quad from scipy.interpolate import CubicSpline atol=1e-13 rtol=1e-10 T = 10 bounds = [(-T,T)] # --- Approach 1 --- # x = np.linspace(0,10*2*np.pi,100) y = np.cos(x) cs = CubicSpline(x, y) def f(t): return cs(t)**2 ctime = time() def cost(t): t = t[0] q = 0 for _ in range(50): q += quad(lambda s: f(s*t), -T, T)[0] return q result = differential_evolution(cost, bounds, atol=atol, tol=rtol, updating='deferred', workers=Pool(cpu_count()).map) print("Approach 1:", time()-ctime) # --- Approach 2 --- # class A(): def define_f(self): x = np.linspace(0,10*2*np.pi,100) y = np.cos(x) cs = CubicSpline(x, y) def f(t): return cs(t)**2 return f f = A().define_f() class B(): def solve(self, f): def cost(t): t = t[0] q = 0 for _ in range(50): q += quad(lambda s: f(s*t), -T, T)[0] return q ctime = time() result = differential_evolution(cost, bounds, atol=atol, tol=rtol, updating='deferred', workers=Pool(cpu_count()).map) print("Approach 2:", time()-ctime) B().solve(f=f) Produces something like: Approach 1: 4.710453510284424 Approach 2: 5.638171672821045 However in my project the second timestamp is an order of magnitude larger. Continue reading...