Last active
October 20, 2023 20:13
-
-
Save JaoodxD/c562972eb0022fc3c8d205c1d51dd0c1 to your computer and use it in GitHub Desktop.
Perf diff
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' | |
var arr = new Array(100).fill(0).map((e, i) => i) | |
var res = 0 | |
function myFor (arr) { | |
var tempSum = 0 | |
for (let j = 0; j < 10_000_000; j++) { | |
for (let index = 0; index < arr.length; index++) { | |
tempSum += arr[index] | |
} | |
} | |
res += tempSum | |
} | |
for (let c = 0; c < 5; c++) { | |
console.time('for') | |
myFor(arr) | |
console.timeEnd('for') // ~1050ms | |
} | |
console.log(res) |
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' | |
var arr = new Array(100).fill(0).map((e, i) => i) | |
var res = 0 | |
function myFor (arr) { | |
for (let j = 0; j < 10_000_000; j++) { | |
var tempSum = 0 | |
for (let index = 0; index < arr.length; index++) { | |
tempSum += arr[index] | |
} | |
res += tempSum | |
} | |
} | |
for (let c = 0; c < 5; c++) { | |
console.time('for') | |
myFor(arr) | |
console.timeEnd('for') // ~800ms | |
} | |
console.log(res) |
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' | |
var arr = new Array(100).fill(0).map((e, i) => i) | |
var res = 0 | |
function myFor (arr) { | |
var temp = 0 | |
for (let j = 0; j < 10_000_000; j++) { | |
var tempSum = 0 | |
for (let index = 0; index < arr.length; index++) { | |
tempSum += arr[index] | |
} | |
temp += tempSum | |
} | |
res += temp | |
} | |
for (let c = 0; c < 5; c++) { | |
console.time('for') | |
myFor(arr) | |
console.timeEnd('for') // ~700ms | |
} | |
console.log(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment