mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
benchmark: add fs warmup to writefile-promises
PR-URL: https://github.com/nodejs/node/pull/59215 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
parent
a93da0a329
commit
cd0c5159e6
1 changed files with 14 additions and 4 deletions
|
@ -39,8 +39,17 @@ function main({ encodingType, duration, concurrent, size }) {
|
|||
let writes = 0;
|
||||
let waitConcurrent = 0;
|
||||
|
||||
const startedAt = Date.now();
|
||||
const endAt = startedAt + (duration * 1000);
|
||||
let startedAt = Date.now();
|
||||
let endAt = startedAt + duration * 1000;
|
||||
|
||||
// fs warmup
|
||||
for (let i = 0; i < concurrent; i++) write();
|
||||
|
||||
writes = 0;
|
||||
waitConcurrent = 0;
|
||||
|
||||
startedAt = Date.now();
|
||||
endAt = startedAt + duration * 1000;
|
||||
|
||||
bench.start();
|
||||
|
||||
|
@ -59,7 +68,8 @@ function main({ encodingType, duration, concurrent, size }) {
|
|||
}
|
||||
|
||||
function write() {
|
||||
fs.promises.writeFile(`${filename}-${filesWritten++}`, chunk, encoding)
|
||||
fs.promises
|
||||
.writeFile(`${filename}-${filesWritten++}`, chunk, encoding)
|
||||
.then(() => afterWrite())
|
||||
.catch((err) => afterWrite(err));
|
||||
}
|
||||
|
@ -72,7 +82,7 @@ function main({ encodingType, duration, concurrent, size }) {
|
|||
writes++;
|
||||
const benchEnded = Date.now() >= endAt;
|
||||
|
||||
if (benchEnded && (++waitConcurrent) === concurrent) {
|
||||
if (benchEnded && ++waitConcurrent === concurrent) {
|
||||
stop();
|
||||
} else if (!benchEnded) {
|
||||
write();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue