paint-brush
Benchmarking Array Traversal in Javascript: How to Go Backwards the Fastestby@wagslane
154 reads

Benchmarking Array Traversal in Javascript: How to Go Backwards the Fastest

by Lane Wagner1mJune 15th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

There are many ways to traverse an array in JavaScript. In this benchmark, we will look at five different ways and the pros and cons of each. These benchmarks were run in a Chrome browser on Codepen. Results will vary by browser/interpreter. The first two times running this after a fresh browser load are quite slow, but then it gets blazingly fast. This is because at each iteration the loop checks against a constant 0 zero value instead of calling the array's.length property.

Company Mentioned

Mention Thumbnail
featured image - Benchmarking Array Traversal in Javascript: How to Go Backwards the Fastest
Lane Wagner HackerNoon profile picture
Lane Wagner

Lane Wagner

@wagslane

Founder of Boot.dev. Whining about coding sins since 2011. Committing coding sins for the same.

About @wagslane
LEARN MORE ABOUT @WAGSLANE'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Lane Wagner HackerNoon profile picture
Lane Wagner@wagslane
Founder of Boot.dev. Whining about coding sins since 2011. Committing coding sins for the same.

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Also published here
Unni