-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: differentiate whatwg and legacy url
- Loading branch information
Showing
7 changed files
with
109 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const url = require('url'); | ||
const assert = require('assert'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
type: common.urlDataTypes, | ||
method: ['legacy', 'whatwg'], | ||
e: [1], | ||
}); | ||
|
||
function main({ type, e }) { | ||
const data = common.bakeUrlData(type, e, false, true); | ||
const obj = url.parse(data[0]); | ||
const noDead = { | ||
protocol: obj.protocol, | ||
auth: obj.auth, | ||
host: obj.host, | ||
hostname: obj.hostname, | ||
port: obj.port, | ||
pathname: obj.pathname, | ||
search: obj.search, | ||
hash: obj.hash, | ||
}; | ||
const len = data.length; | ||
// It's necessary to assign the values to an object | ||
// to avoid loop invariant code motion. | ||
bench.start(); | ||
for (let i = 0; i < len; i++) { | ||
const obj = data[i]; | ||
noDead.protocol = obj.protocol; | ||
noDead.auth = obj.auth; | ||
noDead.host = obj.host; | ||
noDead.hostname = obj.hostname; | ||
noDead.port = obj.port; | ||
noDead.pathname = obj.pathname; | ||
noDead.search = obj.search; | ||
noDead.hash = obj.hash; | ||
} | ||
bench.end(len); | ||
assert.ok(noDead); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const url = require('url'); | ||
const assert = require('assert'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
withBase: ['true', 'false'], | ||
type: common.urlDataTypes, | ||
e: [1], | ||
method: ['legacy', 'whatwg'], | ||
}); | ||
|
||
function main({ e, type }) { | ||
const data = common.bakeUrlData(type, e, false, false); | ||
let result = url.parse(data[0]); // Avoid dead code elimination | ||
|
||
bench.start(); | ||
for (let i = 0; i < data.length; ++i) { | ||
result = url.parse(data[i]); | ||
} | ||
bench.end(data.length); | ||
|
||
assert.ok(result); | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'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, | ||
e: [1], | ||
}); | ||
|
||
function main({ type, e }) { | ||
const data = common.bakeUrlData(type, e, false, true); | ||
const obj = new URL(data[0]); | ||
const noDead = { | ||
protocol: obj.protocol, | ||
auth: `${obj.username}:${obj.password}`, | ||
host: obj.host, | ||
hostname: obj.hostname, | ||
port: obj.port, | ||
pathname: obj.pathname, | ||
search: obj.search, | ||
hash: obj.hash, | ||
}; | ||
const len = data.length; | ||
bench.start(); | ||
for (let i = 0; i < len; i++) { | ||
const obj = data[i]; | ||
noDead.protocol = obj.protocol; | ||
noDead.auth = `${obj.username}:${obj.password}`; | ||
noDead.host = obj.host; | ||
noDead.hostname = obj.hostname; | ||
noDead.port = obj.port; | ||
noDead.pathname = obj.pathname; | ||
noDead.search = obj.search; | ||
noDead.hash = obj.hash; | ||
} | ||
bench.end(len); | ||
assert.ok(noDead); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.