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

Function main

benchmark/crypto/hash-stream-creation.js:16–45  ·  view source on GitHub ↗
({ api, type, len, out, n, algo })

Source from the content-addressed store, hash-verified

14});
15
16function main({ api, type, len, out, n, algo }) {
17 if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) {
18 console.error('Crypto streams not available until v0.10');
19 // Use the legacy, just so that we can compare them.
20 api = 'legacy';
21 }
22
23 let message;
24 let encoding;
25 switch (type) {
26 case 'asc':
27 message = 'a'.repeat(len);
28 encoding = 'ascii';
29 break;
30 case 'utf':
31 message = 'ü'.repeat(len / 2);
32 encoding = 'utf8';
33 break;
34 case 'buf':
35 message = Buffer.alloc(len, 'b');
36 break;
37 default:
38 throw new Error(`unknown message type: ${type}`);
39 }
40
41 const fn = api === 'stream' ? streamWrite : legacyWrite;
42
43 bench.start();
44 fn(algo, message, encoding, n, len, out);
45}
46
47function legacyWrite(algo, message, encoding, n, len, outEnc) {
48 const written = n * len;

Callers

nothing calls this directly

Calls 5

allocMethod · 0.80
fnFunction · 0.50
testMethod · 0.45
errorMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected