Improve random integer array generation
[benchmarks-js.git] / empty-array.js
1 const Benchmark = require('benny')
2 const { generateRandomIntegerArray } = require('./benchmark-utils')
3
4 let testArray = generateRandomIntegerArray(10000)
5
6 Benchmark.suite(
7 'Empty array',
8 Benchmark.add('length = 0', () => {
9 testArray.length = 0
10 }),
11 Benchmark.add('pop loop', async () => {
12 while (testArray.length > 0) {
13 testArray.pop()
14 }
15 }),
16 Benchmark.add('splice', async () => {
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: 'chart.html' }),
30 Benchmark.save({ file: 'empty-array', format: 'table.html' })
31 )