jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Test three methods of retrieving QueryString values with javascript.
<script>
var query = "q=my+search+query&value=55";
window.GetQueryString = function(q) {
return (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i) {
var p = a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(q.split("&"));
};
window.getParameterByName = function(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(query);
if (results == null) return "";
else return decodeURIComponent(results[1].replace(/\+/g, " "));
}
window.getQS = function(qsRAW) {
if(!qsRAW) return {};
var qs = {};
var qsLen = qsRAW.length;
var curKey = "";
var curVal = "";
var compilingKey = true;
for(var i = 0; i < qsLen; i++) {
var char = qsRAW[i];
//If we've hit an equal sign, and we're not on the first character, then
//we should stop compiling our keystring, and should move to the valstring
if(char === "=" && i !== 0 && compilingKey === true) {
compilingKey = false;
} else if(char === "&" || char === ";" || i === qsLen-1) {
var decodedCurVal = decodeURIComponent(curVal);
if(curKey.substr);
//If we already have a value for this key, turn it into an Array and push the next value into it.
if(typeof qs[curKey] !== "undefined") {
if(typeof qs[curKey] === "string") {
var tmpVal = qs[curKey];
qs[curKey] = new Array();
qs[curKey].push(tmpVal);
};
qs[curKey].push(decodedCurVal);
} else {
qs[curKey] = decodedCurVal;
}
curKey = "";
curVal = "";
compilingKey = true;
} else {
if(compilingKey) {
curKey += char;
} else {
curVal += char;
}
}
}
return qs;
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Split method |
| ready |
Regex method |
| ready |
String Scan Method |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.