Skip to content

Commit 6123ed5

Browse files
committed
benchmark: add USVString conversion benchmark
PR-URL: #11436 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b610a4d commit 6123ed5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

benchmark/url/usvstring.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
4+
const inputs = {
5+
valid: 'adsfadsfadsf',
6+
validsurr: '\uda23\ude23\uda1f\udfaa\ud800\udfff\uda23\ude23\uda1f\udfaa' +
7+
'\ud800\udfff',
8+
someinvalid: 'asasfdfasd\uda23',
9+
allinvalid: '\udc45\uda23 \udf00\udc00 \udfaa\uda12 \udc00\udfaa',
10+
nonstring: { toString() { return 'asdf'; } }
11+
};
12+
const bench = common.createBenchmark(main, {
13+
input: Object.keys(inputs),
14+
n: [5e7]
15+
}, {
16+
flags: ['--expose-internals']
17+
});
18+
19+
function main(conf) {
20+
const { toUSVString } = require('internal/url');
21+
const str = inputs[conf.input];
22+
const n = conf.n | 0;
23+
24+
bench.start();
25+
for (var i = 0; i < n; i++)
26+
toUSVString(str);
27+
bench.end(n);
28+
}

0 commit comments

Comments
 (0)