Corrected getParameterByName3

JavaScript performance comparison

Revision 13 of this test case created by Rplus

Info

location.search perormance comparison

Preparation code

<script>
  var query = "?pdq=wrong+search+value&q=my+search+query&value=55";
  var urlObj = {};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Split method
var urlArr = query.substr(1).split('&'),
  urlArrNum = urlArr.length,
  urlArrSplit;

for (var i = 0; i < urlArrNum; i++) {
  urlArrSplit = urlArr[i].split('=');
  urlObj[unescape(urlArrSplit[0])] = urlArrSplit.length > 1 ? unescape(urlArrSplit[1]) : '';
}
pending…
Regex method
query.replace(
  new RegExp("([^?=&]+)(=([^&]*))?", "g"),
  function($0, $1, $2, $3) {
    urlObj[$1] = $3;
  }
);
pending…
Regex method 2
var my_pattern = new RegExp("([^?=&]+)(=([^&]*))?", "g");
query.replace(
  my_pattern,
  function($0, $1, $2, $3) {
    urlObj[$1] = $3;
  }
);
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. Here’s a list of current revisions for this page:

0 comments

Add a comment