We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e2fb4ca commit 848e49cCopy full SHA for 848e49c
1 file changed
benchmark/fs/writefile-promises.js
@@ -39,8 +39,17 @@ function main({ encodingType, duration, concurrent, size }) {
39
let writes = 0;
40
let waitConcurrent = 0;
41
42
- const startedAt = Date.now();
43
- const endAt = startedAt + (duration * 1000);
+ let startedAt = Date.now();
+ 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;
53
54
bench.start();
55
@@ -59,7 +68,8 @@ function main({ encodingType, duration, concurrent, size }) {
59
68
}
60
69
61
70
function write() {
62
- fs.promises.writeFile(`${filename}-${filesWritten++}`, chunk, encoding)
71
+ fs.promises
72
+ .writeFile(`${filename}-${filesWritten++}`, chunk, encoding)
63
73
.then(() => afterWrite())
64
74
.catch((err) => afterWrite(err));
65
75
@@ -72,7 +82,7 @@ function main({ encodingType, duration, concurrent, size }) {
82
writes++;
83
const benchEnded = Date.now() >= endAt;
84
- if (benchEnded && (++waitConcurrent) === concurrent) {
85
+ if (benchEnded && ++waitConcurrent === concurrent) {
76
86
stop();
77
87
} else if (!benchEnded) {
78
88
write();
0 commit comments