Skip to content

Instantly share code, notes, and snippets.

@brian-mann
Last active April 27, 2016 22:59
Show Gist options
  • Select an option

  • Save brian-mann/dd91b95bde09e073a7ba095de05be1d3 to your computer and use it in GitHub Desktop.

Select an option

Save brian-mann/dd91b95bde09e073a7ba095de05be1d3 to your computer and use it in GitHub Desktop.
var vs no var
// 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