Commit | Line | Data |
---|---|---|
2deff321 JB |
1 | const Benchmark = require('benchmark') |
2 | const { LIST_FORMATTER } = require('./benchmark-utils') | |
3 | ||
4 | const suite = new Benchmark.Suite() | |
5 | ||
6 | let testArray = [ | |
7 | 83, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, | |
8 | 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, | |
9 | 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, | |
10 | 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, | |
11 | 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, | |
12 | 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, | |
13 | 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, | |
14 | 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, | |
15 | 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, | |
16 | 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, | |
17 | 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, | |
18 | 36, 28 | |
19 | ] | |
20 | ||
21 | suite | |
22 | .add('length = 0', () => { | |
23 | testArray.length = 0 | |
24 | }) | |
25 | .add('pop loop', async () => { | |
26 | while (testArray.length > 0) { | |
27 | testArray.pop() | |
28 | } | |
29 | }) | |
30 | .add('splice', async () => { | |
31 | testArray.splice(0, testArray.length) | |
32 | }) | |
33 | .add('shift loop', () => { | |
34 | while (testArray.length > 0) { | |
35 | testArray.shift() | |
36 | } | |
37 | }) | |
38 | .add('new init', () => { | |
39 | testArray = [] | |
40 | }) | |
41 | .on('cycle', event => { | |
42 | console.log(event.target.toString()) | |
43 | }) | |
44 | .on('complete', function () { | |
45 | console.log( | |
46 | 'Fastest is ' + LIST_FORMATTER.format(this.filter('fastest').map('name')) | |
47 | ) | |
48 | // eslint-disable-next-line n/no-process-exit | |
49 | process.exit() | |
50 | }) | |
51 | .run() |