Use benny in some benchmarks
[benchmarks-js.git] / empty-array.js
1 const Benchmark = require('benny')
2
3 let testArray = [
4 83, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62,
5 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28,
6 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93,
7 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32,
8 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67,
9 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32,
10 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23,
11 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828,
12 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27,
13 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28,
14 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99,
15 36, 28
16 ]
17
18 Benchmark.suite(
19 'Empty array',
20 Benchmark.add('length = 0', () => {
21 testArray.length = 0
22 }),
23 Benchmark.add('pop loop', async () => {
24 while (testArray.length > 0) {
25 testArray.pop()
26 }
27 }),
28 Benchmark.add('splice', async () => {
29 testArray.splice(0, testArray.length)
30 }),
31 Benchmark.add('shift loop', () => {
32 while (testArray.length > 0) {
33 testArray.shift()
34 }
35 }),
36 Benchmark.add('new init', () => {
37 testArray = []
38 }),
39 Benchmark.cycle(),
40 Benchmark.complete(),
41 Benchmark.save({ file: 'empty-array', format: 'chart.html' }),
42 Benchmark.save({ file: 'empty-array', format: 'table.html' })
43 )