Commit | Line | Data |
---|---|---|
8e5cf49d | 1 | const Benchmark = require('benny') |
feb629fe | 2 | const { generateRandomNumberArray } = require('./benchmark-utils') |
2deff321 | 3 | |
feb629fe | 4 | let testArray = generateRandomNumberArray(10000) |
2deff321 | 5 | |
8e5cf49d JB |
6 | Benchmark.suite( |
7 | 'Empty array', | |
8 | Benchmark.add('length = 0', () => { | |
2deff321 | 9 | testArray.length = 0 |
8e5cf49d | 10 | }), |
e2bfb549 | 11 | Benchmark.add('pop loop', () => { |
2deff321 JB |
12 | while (testArray.length > 0) { |
13 | testArray.pop() | |
14 | } | |
8e5cf49d | 15 | }), |
e2bfb549 | 16 | Benchmark.add('splice', () => { |
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(), | |
fb341cfe JB |
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 }) | |
8e5cf49d | 32 | ) |