| scala> import org.apache.commons.math.distribution.{ExponentialDistributionImpl=>expo} //pc = process customer, with a mean time mu per customer scala> def pc(mu:Int):Double= new expo(mu).sample // q = queue of n customers with mean process time mu scala> def q(n:Int,mu:Int):Double=(1 to n).map(_=>pc(mu)).sum scala> // put 3000 people in 1 queue with mean process time 50 scala> (1 to 1000).map(_=>q(3000,50)).sum/1000 res43: Double = 83107.37275937156 scala> //now put 1000 people each in 3 separate queues with the same mean process time as before scala> (1 to 1000).map(_=>(1 to 3).par.map(_=>q(1000,50)).sum).sum/1000 res45: Double = 200010.29627921886 200010 = ~3x83107, so yeah, single line to 3 cashiers is ~3x faster than a separate line for each cashier. // Now make 1 queue that feeds into shortest of the 3 queues scala> def qq(n:Int,mu:Int)=(1 to 3).par.map(_=>{(1 to n/3).map(_=>pc(mu)).sum}).sum scala> (1 to 10000).map(_=>qq(3000,50)).sum/10000 res70: Double = 141824.974765643 So our single queue feeding into 3 separate queues still beats 3 separate independent queues. edited to address MaysonL's question. |
I don't know what the "par" function does, but assuming it doesn't do anything crazy, the answer for all three of those expressions should be exactly 150,000, because they just reorder the order of summation.