# Parallel quicksort algorithm taking way too long

Below is a Python implementation of the quicksort algorithm using parallelism. It takes about 1 second per every 10 items in the list, which is hilariously unacceptable. Why is it so slow?

from multiprocessing import *

def quicksort(lyst, connection=None):
if len(lyst) > 1:
pivot = lyst.pop(len(lyst)-1)
wall = 0
for i in range(len(lyst)):
if lyst[i] <= pivot:
lyst[wall], lyst[i] = lyst[i], lyst[wall]
wall += 1
Process(target=quicksort, args=(lyst[:wall], sendLeft)).start()
Process(target=quicksort, args=(lyst[wall:], sendRight)).start()
if connection:
connection.send(lyst)
connection.close()
return lyst

if __name__ == '__main__':
quicksort([8,4,6,9,1,3,10,2,7,5])


EDIT Thanks for the responses. As it turns out, switching to Threads and limiting the number of them I was spawning sped things up. However, my linear version of the algorithm still performed better.

• Also, please consider adding your imports so your code will be easier to review. Also consider adding example usage, like how the function will be called on example data and it's result. – Mast Sep 11 '16 at 16:37