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: add a few querystring benchmarks #846

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
33 changes: 33 additions & 0 deletions benchmark/querystring/querystring-parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var common = require('../common.js');
Copy link
Contributor

Choose a reason for hiding this comment

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

why the .js extension?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, I copied from another benchmark, so I left that as-is.

var querystring = require('querystring');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
type: ['noencode', 'encodemany', 'encodelast'],
n: [1e6],
});

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

var inputs = {
noencode: 'foo=bar&baz=quux&xyzzy=thud',
encodemany: '%66%6F%6F=bar&%62%61%7A=quux&xyzzy=%74h%75d',
encodelast: 'foo=bar&baz=quux&xyzzy=thu%64'
};
var input = inputs[type];

// Force-optimize querystring.parse() so that the benchmark doesn't get
// disrupted by the optimizer kicking in halfway through.
for (var name in inputs)
querystring.parse(inputs[name]);

v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(querystring.parse)');

bench.start();
for (var i = 0; i < n; i += 1)
querystring.parse(input);
bench.end(n);
}
45 changes: 45 additions & 0 deletions benchmark/querystring/querystring-stringify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var common = require('../common.js');
var querystring = require('querystring');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
type: ['noencode', 'encodemany', 'encodelast'],
n: [1e6],
});

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

var inputs = {
noencode: {
foo: 'bar',
baz: 'quux',
xyzzy: 'thud'
},
encodemany: {
'\u0080\u0083\u0089': 'bar',
'\u008C\u008E\u0099': 'quux',
xyzzy: '\u00A5q\u00A3r'
},
encodelast: {
foo: 'bar',
baz: 'quux',
xyzzy: 'thu\u00AC'
}
};
var input = inputs[type];

// Force-optimize querystring.stringify() so that the benchmark doesn't get
// disrupted by the optimizer kicking in halfway through.
for (var name in inputs)
querystring.stringify(inputs[name]);

v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(querystring.stringify)');

bench.start();
for (var i = 0; i < n; i += 1)
querystring.stringify(input);
bench.end(n);
}