MCPcopy Index your code
hub / github.com/nodejs/node / main

Function main

benchmark/fs/write-stream-throughput.js:17–78  ·  view source on GitHub ↗
({ dur, encodingType, size })

Source from the content-addressed store, hash-verified

15});
16
17function main({ dur, encodingType, size }) {
18 let encoding;
19
20 let chunk;
21 switch (encodingType) {
22 case 'buf':
23 chunk = Buffer.alloc(size, 'b');
24 break;
25 case 'asc':
26 chunk = 'a'.repeat(size);
27 encoding = 'ascii';
28 break;
29 case 'utf':
30 chunk = 'ü'.repeat(Math.ceil(size / 2));
31 encoding = 'utf8';
32 break;
33 default:
34 throw new Error(`invalid encodingType: ${encodingType}`);
35 }
36
37 try {
38 fs.unlinkSync(filename);
39 } catch {
40 // Continue regardless of error.
41 }
42
43 let started = false;
44 let ended = false;
45
46 const f = fs.createWriteStream(filename);
47 f.on('drain', write);
48 f.on('open', write);
49 f.on('close', done);
50 f.on('finish', () => {
51 ended = true;
52 const written = fs.statSync(filename).size / 1024;
53 try {
54 fs.unlinkSync(filename);
55 } catch {
56 // Continue regardless of error.
57 }
58 bench.end(written / 1024);
59 });
60
61
62 function write() {
63 if (!started) {
64 started = true;
65 setTimeout(() => {
66 f.end();
67 }, dur * 1000);
68 bench.start();
69 }
70
71 while (false !== f.write(chunk, encoding));
72 }
73
74 function done() {

Callers

nothing calls this directly

Calls 6

allocMethod · 0.80
createWriteStreamMethod · 0.65
unlinkSyncMethod · 0.45
onMethod · 0.45
statSyncMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…