Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d23ee89

Browse filesBrowse files
ChALkeRaduh95
authored andcommitted
benchmark: add streaming TextDecoder benchmark
PR-URL: #61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 4bea821 commit d23ee89
Copy full SHA for d23ee89

1 file changed

+55Lines changed: 55 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
5+
const bench = common.createBenchmark(main, {
6+
encoding: ['utf-8', 'utf-16le'],
7+
ignoreBOM: [0, 1],
8+
fatal: [0, 1],
9+
unicode: [0, 1],
10+
len: [256, 1024 * 16, 1024 * 128],
11+
chunks: [10],
12+
n: [1e3],
13+
type: ['SharedArrayBuffer', 'ArrayBuffer', 'Buffer'],
14+
});
15+
16+
const UNICODE_ALPHA = 'Blåbærsyltetøy';
17+
const ASCII_ALPHA = 'Blueberry jam';
18+
19+
function main({ encoding, len, unicode, chunks, n, ignoreBOM, type, fatal }) {
20+
const decoder = new TextDecoder(encoding, { ignoreBOM, fatal });
21+
let buf;
22+
23+
const fill = Buffer.from(unicode ? UNICODE_ALPHA : ASCII_ALPHA, encoding);
24+
25+
switch (type) {
26+
case 'SharedArrayBuffer': {
27+
buf = new SharedArrayBuffer(len);
28+
Buffer.from(buf).fill(fill);
29+
break;
30+
}
31+
case 'ArrayBuffer': {
32+
buf = new ArrayBuffer(len);
33+
Buffer.from(buf).fill(fill);
34+
break;
35+
}
36+
case 'Buffer': {
37+
buf = Buffer.alloc(len, fill);
38+
break;
39+
}
40+
}
41+
42+
const chunk = Math.ceil(len / chunks);
43+
const max = len - chunk;
44+
bench.start();
45+
for (let i = 0; i < n; i++) {
46+
let pos = 0;
47+
while (pos < max) {
48+
decoder.decode(buf.slice(pos, pos + chunk), { stream: true });
49+
pos += chunk;
50+
}
51+
52+
decoder.decode(buf.slice(pos));
53+
}
54+
bench.end(n);
55+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.