Last active
April 27, 2016 22:59
-
-
Save brian-mann/dd91b95bde09e073a7ba095de05be1d3 to your computer and use it in GitHub Desktop.
var vs no var
This file contains hidden or 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
| // if you open your chrome dev tools | |
| // you'll see it log out the performance | |
| // of each iterating in the console | |
| var array = Array(100) | |
| console.time("var") | |
| for (i = 0; i < array.length; i++) { | |
| var e = array[i] | |
| for (j = 0; j < array.length; j++) { | |
| var e2 = array[j] | |
| for (k = 0; k < array.length; k++) { | |
| e * e2 * array[k] | |
| } | |
| } | |
| } | |
| console.timeEnd("var") | |
| console.time("no var") | |
| for (i = 0; i < array.length; i++) { | |
| for (j = 0; j < array.length; j++) { | |
| for (k = 0; k < array.length; k++) { | |
| array[i] * array[j] * array[k] | |
| } | |
| } | |
| } | |
| console.timeEnd("no var") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment