Skip to content

Instantly share code, notes, and snippets.

@fb55
Created May 15, 2012 08:00
Show Gist options
  • Save fb55/2699882 to your computer and use it in GitHub Desktop.
Save fb55/2699882 to your computer and use it in GitHub Desktop.
Node querystring module test
var newQS = require("./new.js"),
oldQS = require("./old.js"),
bench = require("bench");
//taken from https://github.com/joyent/node/blob/master/test/simple/test-querystring.js
var tests = ["foo=918854443121279438895193", "foo=bar", "foo=bar&foo=quux", "foo=1&bar=2", "my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F", "foo%3Dbaz=bar", "foo=baz=bar", "str=foo&arr=1&arr=2&arr=3&somenull=&undef=", " foo = bar ", "foo=%zx", "foo=%EF%BF%BD", "hasOwnProperty=x&toString=foo&valueOf=bar&__defineGetter__=baz", "foo&bar=baz"];
exports.compare = {
"parse from new qs": function(){
return tests.map(newQS.parse);
},
"parse from old qs": function(){
return tests.map(oldQS.parse);
}
};
bench.runMain();
var newQS = require("./new.js"),
oldQS = require("./old.js"),
bench = require("bench");
//taken from https://github.com/joyent/node/blob/master/test/simple/test-querystring.js
var tests = [{"foo": "918854443121279438895193"}, {"foo": "bar"}, {"foo": ["bar", "quux"]}, {"bar": "2", "foo": "1"}, {"my weird field": "q1!2\"'w$5&7/z8)?"}, {"foo=baz": "bar"}, {"foo": "baz=bar"}, {"arr": ["1", "2", "3"], "somenull": "", "str": "foo", "undef": ""}, {" foo ": " bar "}, {"foo": "%zx"}, {"foo": "\ufffd"}, {"bar": "baz", "foo": ""}];
exports.compare = {
"stringify from new qs": function(){
return tests.map(newQS.stringify);
},
"stringify from old qs": function(){
return tests.map(oldQS.stringify);
}
};
bench.runMain();
@isaacs
Copy link

isaacs commented May 15, 2012

Please include old.js and new.js in this gist.

@fb55
Copy link
Author

fb55 commented May 15, 2012

new.js is my updated version, old.js the current node module. As both of them aren't part of my install, I copied them to the same directory as the tests. The names were chosen to distinguish them.

edit: I think it isn't necessary to add them here as they are exactly the same as the linked versions. Downloading them is a simple curl https://github.com/… > file.js (of the raw file).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment