Skip to content

Speed comparisons of three array flattening methods in JavaScript

Notifications You must be signed in to change notification settings

meditari/flatten-3-ways

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Flatten - Served 3 Ways

Speed comparisons of three array flattening methods in JavaScript

  1. Array reduce method based recursion
  2. Single for loop based recursion
  3. 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

About

Speed comparisons of three array flattening methods in JavaScript

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published