| 1 | const Benchmark = require('benny') |
| 2 | const { generateRandomNumberArray } = require('./benchmark-utils') |
| 3 | |
| 4 | const size = 10000 |
| 5 | let testArray = generateRandomNumberArray(size) |
| 6 | |
| 7 | Benchmark.suite( |
| 8 | `Empty array with ${size} elements`, |
| 9 | Benchmark.add('length = 0', () => { |
| 10 | testArray.length = 0 |
| 11 | }), |
| 12 | Benchmark.add('pop loop', () => { |
| 13 | while (testArray.length > 0) { |
| 14 | testArray.pop() |
| 15 | } |
| 16 | }), |
| 17 | Benchmark.add('splice', () => { |
| 18 | testArray.splice(0, testArray.length) |
| 19 | }), |
| 20 | Benchmark.add('shift loop', () => { |
| 21 | while (testArray.length > 0) { |
| 22 | testArray.shift() |
| 23 | } |
| 24 | }), |
| 25 | Benchmark.add('new init', () => { |
| 26 | testArray = [] |
| 27 | }), |
| 28 | Benchmark.cycle(), |
| 29 | Benchmark.complete(), |
| 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 }) |
| 33 | ) |