Add empty object helper implementations benchmark
[benchmarks-js.git] / empty-array.js
1 const Benchmark = require('benny')
2 const { generateRandomNumberArray } = require('./benchmark-utils')
3
4 let testArray = generateRandomNumberArray(10000)
5
6 Benchmark.suite(
7 'Empty array',
8 Benchmark.add('length = 0', () => {
9 testArray.length = 0
10 }),
11 Benchmark.add('pop loop', () => {
12 while (testArray.length > 0) {
13 testArray.pop()
14 }
15 }),
16 Benchmark.add('splice', () => {
17 testArray.splice(0, testArray.length)
18 }),
19 Benchmark.add('shift loop', () => {
20 while (testArray.length > 0) {
21 testArray.shift()
22 }
23 }),
24 Benchmark.add('new init', () => {
25 testArray = []
26 }),
27 Benchmark.cycle(),
28 Benchmark.complete(),
29 Benchmark.save({ file: 'empty-array', format: 'json', details: true }),
30 Benchmark.save({ file: 'empty-array', format: 'chart.html', details: true }),
31 Benchmark.save({ file: 'empty-array', format: 'table.html', details: true })
32 )