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

Function main

benchmark/zlib/pipe.js:24–52  ·  view source on GitHub ↗
({ inputLen, duration, type, algorithm })

Source from the content-addressed store, hash-verified

22};
23
24function main({ inputLen, duration, type, algorithm }) {
25 const buffer = Buffer.alloc(inputLen, fs.readFileSync(__filename));
26 const chunk = type === 'buffer' ? buffer : buffer.toString('utf8');
27
28 const [createCompress, createUncompress] = algorithms[algorithm];
29 const input = createCompress();
30 const output = createUncompress();
31
32 let readFromOutput = 0;
33 input.pipe(output);
34 if (type === 'string')
35 output.setEncoding('utf8');
36 output.on('data', (chunk) => readFromOutput += chunk.length);
37
38 function write() {
39 input.write(chunk, write);
40 }
41
42 bench.start();
43 write();
44
45 setTimeout(() => {
46 // Give result in GBit/s, like the net benchmarks do
47 bench.end(readFromOutput * 8 / (1024 ** 3));
48
49 // Cut off writing the easy way.
50 input.write = () => {};
51 }, duration * 1000);
52}

Callers

nothing calls this directly

Calls 9

allocMethod · 0.80
writeFunction · 0.70
setTimeoutFunction · 0.50
readFileSyncMethod · 0.45
toStringMethod · 0.45
setEncodingMethod · 0.45
onMethod · 0.45
startMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…