Created
October 17, 2023 14:21
-
-
Save danielsan/ed57d03132d0f6bb39298cedcf8b728a to your computer and use it in GitHub Desktop.
Someone said PHP is faster than Javascript
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
console.time('script'); | |
const numbers = Array.from({ length: 10_000_000 }, (_, i) => i); | |
let sum = 0; | |
numbers.forEach((number) => { | |
sum += number; | |
}); | |
console.timeEnd('script'); | |
console.log(`Sum of all numbers is ${sum}`); |
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
console.time('script') | |
const length = 10_000_000 | |
let sum = 0 | |
for (let i = 0; i < length; i++) { | |
sum += i + 1 | |
} | |
console.timeEnd('script') | |
console.log(`Sum of all numbers is ${sum}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment