Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: URLSearchParams v.s. querystring #11170

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/url/legacy-vs-whatwg-url-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function useLegacy(n, input) {
}

function useWHATWG(n, input) {
var noDead = url.parse(input);
var noDead = new URL(input);
bench.start();
for (var i = 0; i < n; i += 1) {
noDead = new URL(input);
Expand Down
61 changes: 61 additions & 0 deletions benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict';
const common = require('../common.js');
const { URLSearchParams } = require('url');
const querystring = require('querystring');

const inputs = {
noencode: 'foo=bar&baz=quux&xyzzy=thud',
encodemany: '%66%6F%6F=bar&%62%61%7A=quux&xyzzy=%74h%75d',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why you didn't include multicharsep and encodefake in the benchmark?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URLSearchParams doesn't support custom separators, so multicharsep is not needed.

I copied the input from url-searchparams-* benchmarks, looks like there isn't encodefake in them.

Copy link
Member

@TimothyGu TimothyGu Feb 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, but I think it's beneficial to have a benchmark case with duplicated & à la #10454, even w/o custom separators.

encodefake: 'foo=%©ar&baz=%A©uux&xyzzy=%©ud',
encodelast: 'foo=bar&baz=quux&xyzzy=thu%64',
multivalue: 'foo=bar&foo=baz&foo=quux&quuy=quuz',
multivaluemany: 'foo=bar&foo=baz&foo=quux&quuy=quuz&foo=abc&foo=def&' +
'foo=ghi&foo=jkl&foo=mno&foo=pqr&foo=stu&foo=vwxyz',
manypairs: 'a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q&r&s&t&u&v&w&x&y&z'
};

const bench = common.createBenchmark(main, {
type: Object.keys(inputs),
method: ['legacy', 'whatwg'],
n: [1e5]
});

function useLegacy(n, input) {
querystring.parse(input);
bench.start();
for (var i = 0; i < n; i += 1) {
querystring.parse(input);
}
bench.end(n);
}

function useWHATWG(n, input) {
new URLSearchParams(input);
bench.start();
for (var i = 0; i < n; i += 1) {
new URLSearchParams(input);
}
bench.end(n);
}

function main(conf) {
const type = conf.type;
const n = conf.n | 0;
const method = conf.method;

const input = inputs[type];
if (!input) {
throw new Error('Unknown input type');
}

switch (method) {
case 'legacy':
useLegacy(n, input);
break;
case 'whatwg':
useWHATWG(n, input);
break;
default:
throw new Error('Unknown method');
}
}
63 changes: 63 additions & 0 deletions benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict';
const common = require('../common.js');
const { URLSearchParams } = require('url');
const querystring = require('querystring');

const inputs = {
noencode: 'foo=bar&baz=quux&xyzzy=thud',
encodemany: '%66%6F%6F=bar&%62%61%7A=quux&xyzzy=%74h%75d',
encodefake: 'foo=%©ar&baz=%A©uux&xyzzy=%©ud',
encodelast: 'foo=bar&baz=quux&xyzzy=thu%64',
multivalue: 'foo=bar&foo=baz&foo=quux&quuy=quuz',
multivaluemany: 'foo=bar&foo=baz&foo=quux&quuy=quuz&foo=abc&foo=def&' +
'foo=ghi&foo=jkl&foo=mno&foo=pqr&foo=stu&foo=vwxyz',
manypairs: 'a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q&r&s&t&u&v&w&x&y&z'
};

const bench = common.createBenchmark(main, {
type: Object.keys(inputs),
method: ['legacy', 'whatwg'],
n: [1e5]
});

function useLegacy(n, input, prop) {
const obj = querystring.parse(input);
querystring.stringify(obj);
bench.start();
for (var i = 0; i < n; i += 1) {
querystring.stringify(obj);
}
bench.end(n);
}

function useWHATWG(n, input, prop) {
const obj = new URLSearchParams(input);
obj.toString();
bench.start();
for (var i = 0; i < n; i += 1) {
obj.toString();
}
bench.end(n);
}

function main(conf) {
const type = conf.type;
const n = conf.n | 0;
const method = conf.method;

const input = inputs[type];
if (!input) {
throw new Error('Unknown input type');
}

switch (method) {
case 'legacy':
useLegacy(n, input);
break;
case 'whatwg':
useWHATWG(n, input);
break;
default:
throw new Error('Unknown method');
}
}
31 changes: 0 additions & 31 deletions benchmark/url/url-searchparams-parse.js

This file was deleted.

35 changes: 0 additions & 35 deletions benchmark/url/url-searchparams-stringifier.js

This file was deleted.