map - a general operation (and not specialized (yet)). Thus, you must insert / remove operations along the path to and from the function. No wonder this is much slower. This, and not the style of the loop used, is the culprit.
The reason this is done is because the code is consistent and easy to maintain. With an infinite number of infinitely cautious people working on the code, each method would be manually created for optimal speed, but it would still be common. The universal utility was preferable to speed, since you can always get the speed back by writing a while loop manually, but if this is not common and you need it, you are stuck.
Improving Scala's performance through operations with primitive collections is the goal, but probably not the highest goal, of the Scala team. For now, if you need speed, use a while loop.
Rex kerr
source share