From: Charles Oliver Nutter Date: 2011-01-15T01:41:34+09:00 Subject: Re: Parallel Assignments and Elegance/Complexity Ratio. On Wed, Jan 12, 2011 at 10:44 AM, Colin Bartlett wrote: > First, whenever I've benchmarked parallel assignment against > individual assignment, I've found the parallel assignment somewhat > slower. The swap is more elegant, but even that seems slower. Parallel assignment is generally slower than straight-up assignment in 1.9 and JRuby because it stands up a full Ruby Array for the RHS and result of the entire assignment expression: ~/projects/jruby ➔ jruby -e "p((a, b, c = 1, 2, 3))" [1, 2, 3] As you would expect this is a significant cost compared to just assigning the values directly. JRuby can improve this when it knows that the assignment is not being used as an expression: ~/projects/jruby ➔ jruby -rbenchmark -e "2.times{ puts Benchmark.measure { 10000000.times {a,b,c=1,2,3} } }" 1.924000 0.000000 1.924000 ( 1.812000) 1.810000 0.000000 1.810000 ( 1.810000) ~/projects/jruby ➔ jruby -rbenchmark -e "2.times{ puts Benchmark.measure { 10000000.times {a,b,c=1,2,3; nil} } }" 1.073000 0.000000 1.073000 ( 0.959000) 0.884000 0.000000 0.884000 ( 0.884000) There are also some implementations that "cheat" (I mean that in the nicest way possible) and don't bother producing that array return value at all, and they perform much better on parallel assignment as a result. - Charlie