Created
February 2, 2023 21:34
-
-
Save midudev/8a52e12fc484c8061ed3df53e29b8955 to your computer and use it in GitHub Desktop.
bench
This file contains hidden or 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
const { beginBench } = require('@agarimo/bench') | |
const bench = beginBench({ | |
duration: 1000, | |
transactionsPerRun: 1000 | |
}) | |
bench.add('forEach', () => { | |
const array = Array.from({ length: 1000 }).map((x, i) => i) | |
let aux = [] | |
array.forEach(n => { | |
if (n % 2 === 0) aux.push(n) | |
}) | |
}) | |
bench.add('for', () => { | |
const array = Array.from({ length: 1000 }).map((x, i) => i) | |
let aux = [] | |
for (let i = 0; i < array.length; i++) { | |
if (array[i] % 2 === 0) aux.push(array[i]) | |
} | |
}) | |
bench.run().then(console.log) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment