add deep merge benchmark
[benchmarks-js.git] / empty-array.mjs
CommitLineData
f522d7b9 1import Benchmark from 'benny'
95d31631 2import { generateRandomNumberArray } from './benchmark-utils.mjs'
2deff321 3
bb578730
JB
4const size = 10000
5let testArray = generateRandomNumberArray(size)
2deff321 6
8e5cf49d 7Benchmark.suite(
bb578730 8 `Empty array with ${size} elements`,
8e5cf49d 9 Benchmark.add('length = 0', () => {
2deff321 10 testArray.length = 0
8e5cf49d 11 }),
e2bfb549 12 Benchmark.add('pop loop', () => {
2deff321
JB
13 while (testArray.length > 0) {
14 testArray.pop()
15 }
8e5cf49d 16 }),
e2bfb549 17 Benchmark.add('splice', () => {
2deff321 18 testArray.splice(0, testArray.length)
8e5cf49d
JB
19 }),
20 Benchmark.add('shift loop', () => {
2deff321
JB
21 while (testArray.length > 0) {
22 testArray.shift()
23 }
8e5cf49d
JB
24 }),
25 Benchmark.add('new init', () => {
2deff321 26 testArray = []
8e5cf49d
JB
27 }),
28 Benchmark.cycle(),
29 Benchmark.complete(),
fb341cfe
JB
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 })
4b16770a
JB
33).catch(err => {
34 console.error(err)
35})