benchmark: add fs warmup to writefile-promises · nodejs/node@848e49c

Original file line numberDiff line numberDiff line change

@@ -39,8 +39,17 @@ function main({ encodingType, duration, concurrent, size }) {

3939

let writes = 0;

4040

let waitConcurrent = 0;

4141
42-

const startedAt = Date.now();

43-

const endAt = startedAt + (duration * 1000);

42+

let startedAt = Date.now();

43+

let endAt = startedAt + duration * 1000;

44+
45+

// fs warmup

46+

for (let i = 0; i < concurrent; i++) write();

47+
48+

writes = 0;

49+

waitConcurrent = 0;

50+
51+

startedAt = Date.now();

52+

endAt = startedAt + duration * 1000;

4453
4554

bench.start();

4655

@@ -59,7 +68,8 @@ function main({ encodingType, duration, concurrent, size }) {

5968

}

6069
6170

function write() {

62-

fs.promises.writeFile(`${filename}-${filesWritten++}`, chunk, encoding)

71+

fs.promises

72+

.writeFile(`${filename}-${filesWritten++}`, chunk, encoding)

6373

.then(() => afterWrite())

6474

.catch((err) => afterWrite(err));

6575

}

@@ -72,7 +82,7 @@ function main({ encodingType, duration, concurrent, size }) {

7282

writes++;

7383

const benchEnded = Date.now() >= endAt;

7484
75-

if (benchEnded && (++waitConcurrent) === concurrent) {

85+

if (benchEnded && ++waitConcurrent === concurrent) {

7686

stop();

7787

} else if (!benchEnded) {

7888

write();