comparison mercurial/worker.py @ 18637:ac4dbceeb14a

worker: partition a list (of tasks) into equal-sized chunks
author Bryan O'Sullivan <bryano@fb.com>
date Sat, 09 Feb 2013 15:51:32 -0800
parents dcb27c153a40
children 047110c0e2a8
comparison
equal deleted inserted replaced
18636:dcb27c153a40 18637:ac4dbceeb14a
50 outweigh the cost of starting them''' 50 outweigh the cost of starting them'''
51 linear = costperop * nops 51 linear = 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]