Merge pull request #115 from jerome-benoit/dependabot/npm_and_yarn/lint-staged-15.2.1
[benchmarks-js.git] / empty-array.mjs
1 import Benchmark from 'benny'
2 import { generateRandomNumberArray } from './benchmark-utils.mjs'
3
4 const size = 10000
5 let testArray = generateRandomNumberArray(size)
6
7 Benchmark.suite(
8 `Empty array with ${size} elements`,
9 Benchmark.add('length = 0', () => {
10 testArray.length = 0
11 }),
12 Benchmark.add('pop loop', () => {
13 while (testArray.length > 0) {
14 testArray.pop()
15 }
16 }),
17 Benchmark.add('splice', () => {
18 testArray.splice(0, testArray.length)
19 }),
20 Benchmark.add('shift loop', () => {
21 while (testArray.length > 0) {
22 testArray.shift()
23 }
24 }),
25 Benchmark.add('new init', () => {
26 testArray = []
27 }),
28 Benchmark.cycle(),
29 Benchmark.complete(),
30 Benchmark.save({ file: 'empty-array', format: 'json', details: true }),
31 Benchmark.save({ file: 'empty-array', format: 'chart.html', details: true }),
32 Benchmark.save({ file: 'empty-array', format: 'table.html', details: true })
33 ).catch(console.error)