-
Notifications
You must be signed in to change notification settings - Fork 35
/
url_parse.js
52 lines (46 loc) · 1.48 KB
/
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
43
44
45
46
47
48
49
50
51
52
/*!
* Copyright (c) 2014-present Cliqz GmbH. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
const readline = require('readline');
const { performance } = require('perf_hooks');
const { URL } = require('url');
// build with node-bench config
const coreUrl = require('../build/core/url');
const urlInfo = require('../build/core/url-info');
const tlds = require('../build/core/tlds');
// collect set of urls to test
const lineReader = readline.createInterface({
input: process.stdin,
});
const urls = []
lineReader.on('line', (line) => {
const url = JSON.parse(line).url;
urls.push(url);
});
function test(fn, repeats = 1) {
const start = performance.now();
for (let r = 0; r < repeats; r += 1) {
for (let i = 0; i < urls.length; i += 1) {
fn(urls[i]);
}
}
return performance.now() - start;
}
lineReader.on('close', () => {
console.log('getDetailsFromUrl', test(coreUrl.getDetailsFromUrl));
console.log('UrlInfo', test(urlInfo.URLInfo.get));
console.log('URL', test(u => new URL(u)));
console.log('tldts', test(tlds.parse));
console.log('UrlInfo: domain extract', test((u) => {
const info = urlInfo.URLInfo.get(u);
info.generalDomain;
}));
console.log('UrlInfo: parameter extract', test((u) => {
const info = urlInfo.URLInfo.get(u);
info.extractKeyValues();
}));
});