refactor: automatically sort imports
[benchmarks-js.git] / empty-array.mjs
CommitLineData
f522d7b9 1import Benchmark from 'benny'
0c01f51c 2
95d31631 3import { generateRandomNumberArray } from './benchmark-utils.mjs'
2deff321 4
bb578730
JB
5const size = 10000
6let testArray = generateRandomNumberArray(size)
2deff321 7
8e5cf49d 8Benchmark.suite(
bb578730 9 `Empty array with ${size} elements`,
8e5cf49d 10 Benchmark.add('length = 0', () => {
2deff321 11 testArray.length = 0
8e5cf49d 12 }),
e2bfb549 13 Benchmark.add('pop loop', () => {
2deff321
JB
14 while (testArray.length > 0) {
15 testArray.pop()
16 }
8e5cf49d 17 }),
e2bfb549 18 Benchmark.add('splice', () => {
2deff321 19 testArray.splice(0, testArray.length)
8e5cf49d
JB
20 }),
21 Benchmark.add('shift loop', () => {
2deff321
JB
22 while (testArray.length > 0) {
23 testArray.shift()
24 }
8e5cf49d
JB
25 }),
26 Benchmark.add('new init', () => {
2deff321 27 testArray = []
8e5cf49d
JB
28 }),
29 Benchmark.cycle(),
30 Benchmark.complete(),
fb341cfe
JB
31 Benchmark.save({ file: 'empty-array', format: 'json', details: true }),
32 Benchmark.save({ file: 'empty-array', format: 'chart.html', details: true }),
33 Benchmark.save({ file: 'empty-array', format: 'table.html', details: true })
4aa2893a 34).catch(console.error)