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 0617c5e

Browse filesBrowse files
joyeecheungtargos
authored andcommitted
benchmark: stablize encode benchmark
- Increase the number of iteration to 1e6 to reduce flakes. 1e4 can introduce flakes even when comparing the main branch against itself - Replace the 1024 * 32 length test with 1024 * 8 since it would otherwise take too long to complete. Remove the 16 length test since it's not too different from 32. - Check the results of the encoding methods at the end. PR-URL: #46658 Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent 069ff1c commit 0617c5e
Copy full SHA for 0617c5e

File tree

Expand file treeCollapse file tree

1 file changed

+22
-17
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+22
-17
lines changed
Open diff view settings
Collapse file

‎benchmark/util/text-encoder.js‎

Copy file name to clipboard
+22-17Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
'use strict';
22

33
const common = require('../common.js');
4+
const assert = require('assert');
45

56
const bench = common.createBenchmark(main, {
6-
len: [16, 32, 256, 1024, 1024 * 32],
7-
n: [1e4],
7+
len: [32, 256, 1024, 1024 * 8],
8+
n: [1e6],
89
type: ['one-byte-string', 'two-byte-string', 'ascii'],
910
op: ['encode', 'encodeInto'],
1011
});
@@ -26,20 +27,24 @@ function main({ n, op, len, type }) {
2627
}
2728

2829
const input = base.repeat(len);
29-
const subarray = new Uint8Array(len);
30-
31-
bench.start();
32-
switch (op) {
33-
case 'encode': {
34-
for (let i = 0; i < n; i++)
35-
encoder.encode(input);
36-
break;
37-
}
38-
case 'encodeInto': {
39-
for (let i = 0; i < n; i++)
40-
encoder.encodeInto(input, subarray);
41-
break;
42-
}
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);
4349
}
44-
bench.end(n);
4550
}

0 commit comments

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