Last active
July 9, 2016 22:59
-
-
Save kessler/74ca5384f62b90880c59ba6a593dab67 to your computer and use it in GitHub Desktop.
benchmark of forward vs backward for loop with node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const size = 10000000 | |
let arr = new Array(size) | |
for (let i = 0; i < size; i++) { | |
arr[i] = i + '' | |
} | |
console.time(`for (let i = 0; i < ${size}; i++) `) | |
for (let i = 0; i < size; i++) { | |
if (arr[i] > size) console.log(1) | |
} | |
console.timeEnd(`for (let i = 0; i < ${size}; i++) `) | |
console.time(`for (let i = ${size}; i >= 0; i--)`) | |
for (let i = size; i >= 0; i--) { | |
if (arr[i] > size) console.log(1) | |
} | |
console.timeEnd(`for (let i = ${size}; i >= 0; i--)`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
on my machine: