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

Written by wagslane | Published 2020/06/15
Tech Story Tags: javascript | programming | tutorial | array | array-backwards | benchmarks | array-es6 | benchmarking-array-traversal

TLDR 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.via the TL;DR App

no story

Written by wagslane | Founder of Boot.dev. Whining about coding sins since 2011. Committing coding sins for the same.
Published by HackerNoon on 2020/06/15