Skip to content

Instantly share code, notes, and snippets.

@midudev
Created February 2, 2023 21:34
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 midudev/8a52e12fc484c8061ed3df53e29b8955 to your computer and use it in GitHub Desktop.
Save midudev/8a52e12fc484c8061ed3df53e29b8955 to your computer and use it in GitHub Desktop.
bench
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