Speed comparisons of three array flattening methods in JavaScript
- Array reduce method based recursion
- Single
for
loop based recursion - Nested
for
loop based recursion
Example Output:
Performing 100 iterations of reduce based flatten method...
Execution time for reduce based flatten method: 898.1500000000002 ms
Performing 100 iterations of single "for" loop flatten method...
Execution time for single "for" loop flatten method: 260.09999999999957 ms
Performing 100 iterations of nested "for" loop flatten method...
Execution time for nested "for" loop flatten method: 25.639999999999645 ms
Single "for" loop is 71.04% faster than reduce
Nested "for" loop is 90.14% faster than single "for" loop.
Nested "for" loop is 97.15% faster than reduce