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

Function main

benchmark/util/text-encoder.js:13–50  ·  view source on GitHub ↗
({ n, op, len, type })

Source from the content-addressed store, hash-verified

11});
12
13function main({ n, op, len, type }) {
14 const encoder = new TextEncoder();
15 let base = '';
16
17 switch (type) {
18 case 'ascii':
19 base = 'a';
20 break;
21 case 'one-byte-string':
22 base = '\xff';
23 break;
24 case 'two-byte-string':
25 base = 'ğ';
26 break;
27 }
28
29 const input = base.repeat(len);
30 if (op === 'encode') {
31 const expected = encoder.encode(input);
32 let result;
33 bench.start();
34 for (let i = 0; i < n; i++)
35 result = encoder.encode(input);
36 bench.end(n);
37 assert.deepStrictEqual(result, expected);
38 } else {
39 const expected = new Uint8Array(len);
40 const subarray = new Uint8Array(len);
41 const expectedStats = encoder.encodeInto(input, expected);
42 let result;
43 bench.start();
44 for (let i = 0; i < n; i++)
45 result = encoder.encodeInto(input, subarray);
46 bench.end(n);
47 assert.deepStrictEqual(subarray, expected);
48 assert.deepStrictEqual(result, expectedStats);
49 }
50}

Callers

nothing calls this directly

Calls 4

encodeMethod · 0.95
encodeIntoMethod · 0.95
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…