blob: 5523e549ceb233f1a835687c3b421d0097457301 (
plain)
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
53
|
'use strict';
const common = require('../common.js');
const url = require('url');
const URL = url.URL;
const assert = require('assert');
const bench = common.createBenchmark(main, {
type: common.urlDataTypes,
method: ['legacy', 'whatwg'],
e: [1]
});
function useLegacy(data) {
const obj = url.parse(data[0]);
const len = data.length;
var noDead = url.format(obj);
bench.start();
for (let i = 0; i < len; i++) {
noDead = data[i].toString();
}
bench.end(len);
return noDead;
}
function useWHATWG(data) {
const obj = new URL(data[0]);
const len = data.length;
var noDead = obj.toString();
bench.start();
for (let i = 0; i < len; i++) {
noDead = data[i].toString();
}
bench.end(len);
return noDead;
}
function main({ type, e, method }) {
const data = common.bakeUrlData(type, e, false, false);
var noDead; // Avoid dead code elimination.
switch (method) {
case 'legacy':
noDead = useLegacy(data);
break;
case 'whatwg':
noDead = useWHATWG(data);
break;
default:
throw new Error(`Unknown method ${method}`);
}
assert.ok(noDead);
}
|