5 ms·
One thing to note though is that forEach and reduce can both be /theoretically/ faster; for and while loops both imply an order in processing the list, whilst f
by Cthulhu_ 13y ago
One thing to note though is that forEach and reduce can both be /theoretically/ faster; for and while loops both imply an order in processing the list, whilst forEach and definitely reduce don't; in theory, the JS interpreter can take the array, split it up into chunks (one for each core / thread), and process the list in parallel, which would / could produce results faster.
But, atm, functional operations on lists are still executed single-threaded. Wouldn't mind seeing a WebWorker implementation, for example. Although somehow I think the overhead for a relatively simple calculation like this would negate the results.