Skip to content

Commit 35ed799

Browse files
mscdexbrendanashworth
authored andcommitted
benchmark: add a few querystring benchmarks
PR-URL: #847 Reviewed-By: Brendan Ashworth <[email protected]>
1 parent d53b636 commit 35ed799

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var common = require('../common.js');
2+
var querystring = require('querystring');
3+
var v8 = require('v8');
4+
5+
var bench = common.createBenchmark(main, {
6+
type: ['noencode', 'encodemany', 'encodelast'],
7+
n: [1e6],
8+
});
9+
10+
function main(conf) {
11+
var type = conf.type;
12+
var n = conf.n | 0;
13+
14+
var inputs = {
15+
noencode: 'foo=bar&baz=quux&xyzzy=thud',
16+
encodemany: '%66%6F%6F=bar&%62%61%7A=quux&xyzzy=%74h%75d',
17+
encodelast: 'foo=bar&baz=quux&xyzzy=thu%64'
18+
};
19+
var input = inputs[type];
20+
21+
// Force-optimize querystring.parse() so that the benchmark doesn't get
22+
// disrupted by the optimizer kicking in halfway through.
23+
for (var name in inputs)
24+
querystring.parse(inputs[name]);
25+
26+
v8.setFlagsFromString('--allow_natives_syntax');
27+
eval('%OptimizeFunctionOnNextCall(querystring.parse)');
28+
29+
bench.start();
30+
for (var i = 0; i < n; i += 1)
31+
querystring.parse(input);
32+
bench.end(n);
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var common = require('../common.js');
2+
var querystring = require('querystring');
3+
var v8 = require('v8');
4+
5+
var bench = common.createBenchmark(main, {
6+
type: ['noencode', 'encodemany', 'encodelast'],
7+
n: [1e6],
8+
});
9+
10+
function main(conf) {
11+
var type = conf.type;
12+
var n = conf.n | 0;
13+
14+
var inputs = {
15+
noencode: {
16+
foo: 'bar',
17+
baz: 'quux',
18+
xyzzy: 'thud'
19+
},
20+
encodemany: {
21+
'\u0080\u0083\u0089': 'bar',
22+
'\u008C\u008E\u0099': 'quux',
23+
xyzzy: '\u00A5q\u00A3r'
24+
},
25+
encodelast: {
26+
foo: 'bar',
27+
baz: 'quux',
28+
xyzzy: 'thu\u00AC'
29+
}
30+
};
31+
var input = inputs[type];
32+
33+
// Force-optimize querystring.stringify() so that the benchmark doesn't get
34+
// disrupted by the optimizer kicking in halfway through.
35+
for (var name in inputs)
36+
querystring.stringify(inputs[name]);
37+
38+
v8.setFlagsFromString('--allow_natives_syntax');
39+
eval('%OptimizeFunctionOnNextCall(querystring.stringify)');
40+
41+
bench.start();
42+
for (var i = 0; i < n; i += 1)
43+
querystring.stringify(input);
44+
bench.end(n);
45+
}

0 commit comments

Comments
 (0)