Skip to content

Instantly share code, notes, and snippets.

@danielsan
Created October 17, 2023 14:21
Show Gist options
  • Save danielsan/ed57d03132d0f6bb39298cedcf8b728a to your computer and use it in GitHub Desktop.
Save danielsan/ed57d03132d0f6bb39298cedcf8b728a to your computer and use it in GitHub Desktop.
Someone said PHP is faster than Javascript
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}`);
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