loop.js
This file
Path
benchmarks/utils/src/loop.js
37 lines 路 593 bytes 路 JavaScript
Last changed by
Not known.
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738import { run, group, bench } from 'mitata'
const arr = new Array(100000).fill(Math.random())
bench('noop', () => {})
group('loop', () => { bench('map', () => { const newArr = [] arr.map((e) => { newArr.push(e) }) })
bench('forEach', () => { const newArr = [] arr.forEach((e) => { newArr.push(e) }) })
bench('for of', () => { const newArr = [] for (const e of arr) { newArr.push(e) } })
bench('for', () => { const newArr = [] for (let i = 0; i < arr.length; i++) { newArr.push(arr[i]) } })})
run()