d0d1381154170fa72776fa506f33def2aa075c30
1 const Benchmark
= require('benny')
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,
22 function loopMax (values
) {
24 for (const value
of values
) {
25 if (value
> max
) max
= value
34 function reduceTernaryMax (values
) {
35 return values
.reduce((a
, b
) => (a
> b
? a
: b
), -Infinity
)
42 function reduceMathMax (values
) {
43 return values
.reduce((a
, b
) => Math
.max(a
, b
), -Infinity
)
50 function sortMax (values
) {
51 return values
.sort((a
, b
) => b
- a
)[0]
56 Benchmark
.add('Math.max', () => {
57 Math
.max(...testArray
)
59 Benchmark
.add('loopMax', () => {
62 Benchmark
.add('reduceTernaryMax', () => {
63 reduceTernaryMax(testArray
)
65 Benchmark
.add('reduceMathMax', () => {
66 reduceMathMax(testArray
)
68 Benchmark
.add('sortMax', () => {
73 Benchmark
.save({ file
: 'max', format
: 'chart.html' }),
74 Benchmark
.save({ file
: 'max', format
: 'table.html' })