forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwhatwg-url-parse.js
42 lines (37 loc) · 1.03 KB
/
whatwg-url-parse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
const common = require('../common.js');
const url = require('url');
const URL = url.URL;
const assert = require('assert');
const bench = common.createBenchmark(main, {
withBase: ['true', 'false'],
type: common.urlDataTypes,
e: [1],
});
function useWHATWGWithBase(data) {
const len = data.length;
let result = new URL(data[0][0], data[0][1]); // Avoid dead code elimination
bench.start();
for (let i = 0; i < len; ++i) {
const item = data[i];
result = new URL(item[0], item[1]);
}
bench.end(len);
return result;
}
function useWHATWGWithoutBase(data) {
const len = data.length;
let result = new URL(data[0]); // Avoid dead code elimination
bench.start();
for (let i = 0; i < len; ++i) {
result = new URL(data[i]);
}
bench.end(len);
return result;
}
function main({ e, type, withBase }) {
withBase = withBase === 'true';
const data = common.bakeUrlData(type, e, withBase, false);
const noDead = withBase ? useWHATWGWithBase(data) : useWHATWGWithoutBase(data);
assert.ok(noDead);
}