QueryString with javascript
JavaScript performance comparison
Preparation code
<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(window.location.href);
if (results == null) return "";
else return decodeURIComponent(results[1].replace(/\+/g, " "));
}
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test | Ops/sec | |
---|---|---|
Split method
|
|
pending… |
Regex method
|
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit
to the URL.
- Revision 1: published BrunoLM
- Revision 2: published Andrew Petersen
- Revision 3: published Andy E
- Revision 4: published
- Revision 5: published
- Revision 8: published Justin
- Revision 9: published Martin
- Revision 10: published rufwork
- Revision 12: published amin
- Revision 13: published Rplus
- Revision 14: published
- Revision 15: published falcacibar
- Revision 16: published
- Revision 17: published
- Revision 20: published Tri
- Revision 22: published ale
- Revision 23: published ale
- Revision 24: published
- Revision 25: published
- Revision 26: published
- Revision 27: published
- Revision 29: published Jared Savage
- Revision 30: published Jared Savage
- Revision 31: published Dennis
- Revision 32: published Dennis
- Revision 33: published uyguyt
- Revision 34: published
- Revision 40: published thdoan
- Revision 42: published Arthur Araújo
- Revision 43: published Arthur Araújo
- Revision 44: published Arthur Araújo
- Revision 45: published Amirali Nurmagomedov
- Revision 46: published Amirali Nurmagomedov
- Revision 47: published Amirali Nurmagomedov
1 Comment
sdddddddddddddddsd