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

Function main

benchmark/fs/readfile-partitioned.js:25–105  ·  view source on GitHub ↗
({ len, duration, concurrent, encoding })

Source from the content-addressed store, hash-verified

23});
24
25function main({ len, duration, concurrent, encoding }) {
26 try {
27 fs.unlinkSync(filename);
28 } catch {
29 // Continue regardless of error.
30 }
31 let data = Buffer.alloc(len, 'x');
32 fs.writeFileSync(filename, data);
33 data = null;
34
35 const zipData = Buffer.alloc(1024, 'a');
36
37 let waitConcurrent = 0;
38
39 // Plus one because of zip
40 const targetConcurrency = concurrent + 1;
41 const startedAt = Date.now();
42 const endAt = startedAt + (duration * 1000);
43
44 let reads = 0;
45 let zips = 0;
46
47 bench.start();
48
49 function stop() {
50 const totalOps = reads + zips;
51 bench.end(totalOps);
52
53 try {
54 fs.unlinkSync(filename);
55 } catch {
56 // Continue regardless of error.
57 }
58 }
59
60 function read() {
61 fs.readFile(filename, encoding, afterRead);
62 }
63
64 function afterRead(er, data) {
65 if (er) {
66 throw er;
67 }
68
69 if (data.length !== len)
70 throw new Error('wrong number of bytes returned');
71
72 reads++;
73 const benchEnded = Date.now() >= endAt;
74
75 if (benchEnded && (++waitConcurrent) === targetConcurrency) {
76 stop();
77 } else if (!benchEnded) {
78 read();
79 }
80 }
81
82 function zip() {

Callers

nothing calls this directly

Calls 7

zipFunction · 0.85
allocMethod · 0.80
nowMethod · 0.80
readFunction · 0.70
unlinkSyncMethod · 0.45
writeFileSyncMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected