##// END OF EJS Templates
worker: partition a list (of tasks) into equal-sized chunks
Bryan O'Sullivan -
r18637:ac4dbcee default
parent child Browse files
Show More
@@ -52,3 +52,16 b' def worthwhile(ui, costperop, nops):'
52 workers = _numworkers(ui)
52 workers = _numworkers(ui)
53 benefit = linear - (_startupcost * workers + linear / workers)
53 benefit = linear - (_startupcost * workers + linear / workers)
54 return benefit >= 0.15
54 return benefit >= 0.15
55
56 def partition(lst, nslices):
57 '''partition a list into N slices of equal size'''
58 n = len(lst)
59 chunk, slop = n / nslices, n % nslices
60 end = 0
61 for i in xrange(nslices):
62 start = end
63 end = start + chunk
64 if slop:
65 end += 1
66 slop -= 1
67 yield lst[start:end]
General Comments 0
You need to be logged in to leave comments. Login now