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

Function main

benchmark/fs/bench-opendir.js:14–53  ·  view source on GitHub ↗
({ n, dir, mode, bufferSize })

Source from the content-addressed store, hash-verified

12});
13
14async function main({ n, dir, mode, bufferSize }) {
15 const fullPath = path.resolve(__dirname, '../../', dir);
16
17 bench.start();
18
19 let counter = 0;
20 for (let i = 0; i < n; i++) {
21 if (mode === 'async') {
22 const dir = await fs.promises.opendir(fullPath, { bufferSize });
23 // eslint-disable-next-line no-unused-vars
24 for await (const entry of dir)
25 counter++;
26 } else if (mode === 'callback') {
27 const dir = await fs.promises.opendir(fullPath, { bufferSize });
28 await new Promise((resolve, reject) => {
29 function read() {
30 dir.read((err, entry) => {
31 if (err) {
32 reject(err);
33 } else if (entry === null) {
34 resolve(dir.close());
35 } else {
36 counter++;
37 read();
38 }
39 });
40 }
41
42 read();
43 });
44 } else {
45 const dir = fs.opendirSync(fullPath, { bufferSize });
46 while (dir.readSync() !== null)
47 counter++;
48 dir.closeSync();
49 }
50 }
51
52 bench.end(counter);
53}

Callers

nothing calls this directly

Calls 8

opendirMethod · 0.80
opendirSyncMethod · 0.80
readFunction · 0.70
resolveMethod · 0.45
startMethod · 0.45
readSyncMethod · 0.45
closeSyncMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…