-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: add a few querystring benchmarks
PR-URL: #847 Reviewed-By: Brendan Ashworth <[email protected]>
- Loading branch information
1 parent
d53b636
commit 35ed799
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
35ed799
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correction: PR-URL: #846.