Skip to content

Commit

Permalink
benchmark: add a few querystring benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
mscdex committed Feb 15, 2015
1 parent d53b636 commit a768c03
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
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');
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);
}

0 comments on commit a768c03

Please sign in to comment.