mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01: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
|
|
@ -39,8 +39,17 @@ function main({ encodingType, duration, concurrent, size }) {
|
||||||
let writes = 0;
|
let writes = 0;
|
||||||
let waitConcurrent = 0;
|
let waitConcurrent = 0;
|
||||||
|
|
||||||
const startedAt = Date.now();
|
let startedAt = Date.now();
|
||||||
const endAt = startedAt + (duration * 1000);
|
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();
|
bench.start();
|
||||||
|
|
||||||
|
|
@ -59,7 +68,8 @@ function main({ encodingType, duration, concurrent, size }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function write() {
|
function write() {
|
||||||
fs.promises.writeFile(`${filename}-${filesWritten++}`, chunk, encoding)
|
fs.promises
|
||||||
|
.writeFile(`${filename}-${filesWritten++}`, chunk, encoding)
|
||||||
.then(() => afterWrite())
|
.then(() => afterWrite())
|
||||||
.catch((err) => afterWrite(err));
|
.catch((err) => afterWrite(err));
|
||||||
}
|
}
|
||||||
|
|
@ -72,7 +82,7 @@ function main({ encodingType, duration, concurrent, size }) {
|
||||||
writes++;
|
writes++;
|
||||||
const benchEnded = Date.now() >= endAt;
|
const benchEnded = Date.now() >= endAt;
|
||||||
|
|
||||||
if (benchEnded && (++waitConcurrent) === concurrent) {
|
if (benchEnded && ++waitConcurrent === concurrent) {
|
||||||
stop();
|
stop();
|
||||||
} else if (!benchEnded) {
|
} else if (!benchEnded) {
|
||||||
write();
|
write();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user