Skip to content

Instantly share code, notes, and snippets.

@Leask
Created April 18, 2018 16:22
Show Gist options
  • Save Leask/5fbf52db3f1311c403f86ba3ac5f4482 to your computer and use it in GitHub Desktop.
Save Leask/5fbf52db3f1311c403f86ba3ac5f4482 to your computer and use it in GitHub Desktop.
Simple Javascript speed testing
let a = [
[1, 2, 3, 4],
[1, 2, 3, 4],
[1, 2, 3, 4],
[1, 2, 3, 4],
];
let t1 = new Date().getTime();
for (let i = 0; i < 1000000; i++) {
for (let j in a) {
for (let k in a[j]) {
let x1 = a[j];
let x2 = a[j];
let x3 = a[j];
let x4 = a[j];
// console.log(x);
}
}
}
let t2 = new Date().getTime();
console.log(t2 - t1);
for (let i = 0; i < 1000000; i++) {
for (let j in a) {
let y = a[j];
for (let k in y) {
let x1 = y[k];
let x2 = y[k];
let x3 = y[k];
let x4 = y[k];
// console.log(x);
}
}
}
let t3 = new Date().getTime();
console.log(t3 - t2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment