I\'ve compaired the scala version
(BigInt(1) to BigInt(50000)).reduce(_ * _)
to the python version
reduce(lambda x,y: x*y, rang
Another trick here could be to try both reduceLeft
and reduceRight
to see what is fastest. On your example I get a much faster execution of reduceRight
:
scala> timed { (BigInt(1) to BigInt(50000)).reduceLeft(_ * _) }
Took: 4605 ms
scala> timed { (BigInt(1) to BigInt(50000)).reduceRight(_ * _) }
Took: 2004 ms
Same difference between foldLeft
and foldRight
. Guess it matters what side of the tree you start reducing from :)