repositories
/
benchmarks-js.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bump husky from 8.0.2 to 8.0.3
[benchmarks-js.git]
/
max.js
diff --git
a/max.js
b/max.js
index 367a859126e91b8f2b70a04a41422f31f2951a22..be3f7819314f12757d34e124b445d4941a85a114 100644
(file)
--- a/
max.js
+++ b/
max.js
@@
-1,11
+1,13
@@
const Benchmark = require('benny')
const Benchmark = require('benny')
-const { generateRandom
Integ
erArray } = require('./benchmark-utils')
+const { generateRandom
Numb
erArray } = require('./benchmark-utils')
-const testArray = generateRandomIntegerArray(10000)
+const size = 10000
+const testArray = generateRandomNumberArray(size)
/**
*
* @param values
/**
*
* @param values
+ * @returns
*/
function loopMax (values) {
let max = -Infinity
*/
function loopMax (values) {
let max = -Infinity
@@
-18,6
+20,7
@@
function loopMax (values) {
/**
*
* @param values
/**
*
* @param values
+ * @returns
*/
function reduceTernaryMax (values) {
return values.reduce((a, b) => (a > b ? a : b), -Infinity)
*/
function reduceTernaryMax (values) {
return values.reduce((a, b) => (a > b ? a : b), -Infinity)
@@
-26,6
+29,7
@@
function reduceTernaryMax (values) {
/**
*
* @param values
/**
*
* @param values
+ * @returns
*/
function reduceMathMax (values) {
return values.reduce((a, b) => Math.max(a, b), -Infinity)
*/
function reduceMathMax (values) {
return values.reduce((a, b) => Math.max(a, b), -Infinity)
@@
-34,13
+38,14
@@
function reduceMathMax (values) {
/**
*
* @param values
/**
*
* @param values
+ * @returns
*/
function sortMax (values) {
return values.sort((a, b) => b - a)[0]
}
Benchmark.suite(
*/
function sortMax (values) {
return values.sort((a, b) => b - a)[0]
}
Benchmark.suite(
-
'max'
,
+
`Max from ${size} numbers`
,
Benchmark.add('Math.max', () => {
Math.max(...testArray)
}),
Benchmark.add('Math.max', () => {
Math.max(...testArray)
}),