scala - Parallel operation on list with future -
i wondering general advise if following made sense.
i have list, need filter according following criteria: let list contain things of type a, b, c , d , want take n0 elt of a, n1 elt of b, n2 elt of c , n3 elt of d , make 1 list out of it.
the iterative approach pretty clean (i.e. going on list, using 4 counters, adding elt each list until each respective counter reached limit i.e. n1, n2, n3, n4), colleague @ work told me take advantage of multiple cpu , parallelize operation using future.
in other words, launching 4 future operation filter list, , drop if applies (i.e.resultinglist > nx), "resultinglist.size - n0 or n1 or n2 or n3 or n4". await result , combine list.
i think overkill use iteratively pretty easily. wonder people think that. yes can run test , compare speed, raise question of, when can ensure taking advantage of multiple cpu architecture. because indeed understand motivation behind suggestion. however, did not know how tell might counter productive. both stuck in debate , enable state if situation or bad situation use parallelization. in other word did not have criterion. testing way know ?
many thanks,
m
avoid premature optimization.
if benchmark , find doing slow requirement incorporate parallel version , benchmarking.
Comments
Post a Comment