mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
a365bb9cb1
This patch: - Introduces `common.bakeUrlData` which can be used to pre-generate the data set for the URL benchmarks to loop through instead of looping over a constant. - Add the option to use WPT data in benchmarks for better diversity in the input - Add the option to benchmark URL parsing with base URLs (whatwg only) - Moves the data in `benchmark/fixtures/url-inputs.js` to `benchmark/common.js` PR-URL: https://github.com/nodejs/node/pull/24302 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
55 lines
1.1 KiB
JavaScript
55 lines
1.1 KiB
JavaScript
'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 (var 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 (var i = 0; i < len; i++) {
|
|
noDead = data[i].toString();
|
|
}
|
|
bench.end(len);
|
|
return noDead;
|
|
}
|
|
|
|
function main({ type, e, method }) {
|
|
e = +e;
|
|
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);
|
|
}
|