-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
119 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict' | ||
|
||
const parallelRequests = parseInt(process.env.PARALLEL, 10) || 100 | ||
|
||
function makeParallelRequests (cb) { | ||
const promises = new Array(parallelRequests) | ||
for (let i = 0; i < parallelRequests; ++i) { | ||
promises[i] = new Promise(cb) | ||
} | ||
return Promise.all(promises) | ||
} | ||
|
||
function printResults (results) { | ||
// Sort results by least performant first, then compare relative performances and also printing padding | ||
let last | ||
|
||
const rows = Object.entries(results) | ||
// If any failed, put on the top of the list, otherwise order by mean, ascending | ||
.sort((a, b) => (!a[1].success ? -1 : b[1].mean - a[1].mean)) | ||
.map(([name, result]) => { | ||
if (!result.success) { | ||
return { | ||
Tests: name, | ||
Samples: result.size, | ||
Result: 'Errored', | ||
Tolerance: 'N/A', | ||
'Difference with Slowest': 'N/A' | ||
} | ||
} | ||
|
||
// Calculate throughput and relative performance | ||
const { size, mean, standardError } = result | ||
const relative = last !== 0 ? (last / mean - 1) * 100 : 0 | ||
|
||
// Save the slowest for relative comparison | ||
if (typeof last === 'undefined') { | ||
last = mean | ||
} | ||
|
||
return { | ||
Tests: name, | ||
Samples: size, | ||
Result: `${((parallelRequests * 1e9) / mean).toFixed(2)} req/sec`, | ||
Tolerance: `± ${((standardError / mean) * 100).toFixed(2)} %`, | ||
'Difference with slowest': | ||
relative > 0 ? `+ ${relative.toFixed(2)} %` : '-' | ||
} | ||
}) | ||
|
||
return console.table(rows) | ||
} | ||
|
||
module.exports = { makeParallelRequests, printResults } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters