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 b95e5d7

Browse filesBrowse files
TrottMyles Borins
authored andcommitted
benchmark: add benchmark for url.format()
PR-URL: #7250 Reviewed-By: Brian White <mscdex@mscdex.net>
1 parent 7182f5f commit b95e5d7
Copy full SHA for b95e5d7

File tree

Expand file treeCollapse file tree

1 file changed

+33
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+33
-0
lines changed
Open diff view settings
Collapse file

‎benchmark/url/url-format.js‎

Copy file name to clipboard
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const url = require('url');
4+
const v8 = require('v8');
5+
6+
const bench = common.createBenchmark(main, {
7+
type: 'one two'.split(' '),
8+
n: [25e6]
9+
});
10+
11+
function main(conf) {
12+
const type = conf.type;
13+
const n = conf.n | 0;
14+
15+
const inputs = {
16+
one: {slashes: true, host: 'localhost'},
17+
two: {protocol: 'file:', pathname: '/foo'},
18+
};
19+
const input = inputs[type] || '';
20+
21+
// Force-optimize url.format() so that the benchmark doesn't get
22+
// disrupted by the optimizer kicking in halfway through.
23+
for (const name in inputs)
24+
url.format(inputs[name]);
25+
26+
v8.setFlagsFromString('--allow_natives_syntax');
27+
eval('%OptimizeFunctionOnNextCall(url.format)');
28+
29+
bench.start();
30+
for (var i = 0; i < n; i += 1)
31+
url.format(input);
32+
bench.end(n);
33+
}

0 commit comments

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