Commit | Line | Data |
---|---|---|
8e5cf49d | 1 | const Benchmark = require('benny') |
ed40d2b0 | 2 | const { generateRandomIntegerArray } = require('./benchmark-utils') |
2deff321 | 3 | |
ed40d2b0 | 4 | let testArray = generateRandomIntegerArray(10000) |
2deff321 | 5 | |
8e5cf49d JB |
6 | Benchmark.suite( |
7 | 'Empty array', | |
8 | Benchmark.add('length = 0', () => { | |
2deff321 | 9 | testArray.length = 0 |
8e5cf49d JB |
10 | }), |
11 | Benchmark.add('pop loop', async () => { | |
2deff321 JB |
12 | while (testArray.length > 0) { |
13 | testArray.pop() | |
14 | } | |
8e5cf49d JB |
15 | }), |
16 | Benchmark.add('splice', async () => { | |
2deff321 | 17 | testArray.splice(0, testArray.length) |
8e5cf49d JB |
18 | }), |
19 | Benchmark.add('shift loop', () => { | |
2deff321 JB |
20 | while (testArray.length > 0) { |
21 | testArray.shift() | |
22 | } | |
8e5cf49d JB |
23 | }), |
24 | Benchmark.add('new init', () => { | |
2deff321 | 25 | testArray = [] |
8e5cf49d JB |
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 | ) |