Skip to content

Instantly share code, notes, and snippets.

@connor4312
Last active March 25, 2021 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save connor4312/07da143059161a301292b0fe5951f0c1 to your computer and use it in GitHub Desktop.
Save connor4312/07da143059161a301292b0fe5951f0c1 to your computer and use it in GitHub Desktop.
// run with `matcha bench.js`
const cars = ['Tesla', 'Tata', 'Ford', 'Land Rover', 'Audi'];
let x;
bench('for-let', () => {
for (let i = 0; i < cars.length; i++) {
x = cars[i];
}
});
bench('forEach', () => {
cars.forEach(car => {
x = car;
});
});
bench('for of', () => {
for (const car of cars) {
x = car;
}
});
bench('for in', () => {
for (const car in cars) {
x = car;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment