vectorize and parallelize if it's add compute?
<p>What's the most efficient technique and Why?</p>

<pre><code>min_dist = 999999999999999999999999999999999999999999
    for i in range(len(self.data)):
        data = self.data[i]
        dist = MySuperLongFunction(data)
        if dist &lt; min_dist:
            min_dist = dist
    return min_dist
</code></pre>

<p>or</p>

<pre><code>vdist = [0]*len(self.data)
    for i in range(len(self.data)):
        data = self.data[i]
        dist = MySuperLongFunction(data)
        vdist[i] = dist
 return min(vdist)
</code></pre>

<p>I know that the min(vdist) add compute to do but the second one can be parallelize verry easily because the for don't depend of previous itÃ©ration so I can compute 8 time at one the MySuperLongFunction(data). So what's the most effective? </p>

<p>You need to generate the function value for each input data in self.data, hence, <code>DARRAY = [MySuperLongFunction(x) for x in self.data]</code> has to be computed no matter what.
As you already pointed out, computing <code>DARRAY</code> could be parallelized, hence, we are left with returning the <code>min</code> value in this case,</p>

<p>So, i would say it's <code>min([MySuperLongFunction(x) for x in self.data])</code></p>

python multithreading vectorization