Corrected getParameterByName3 (v13)

Revision 13 of this benchmark created by Rplus on


Description

location.search perormance comparison

Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/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]) : '';
}
ready
Regex method
query.replace(
  new RegExp("([^?=&]+)(=([^&]*))?", "g"),
  function($0, $1, $2, $3) {
    urlObj[$1] = $3;
  }
);
ready
Regex method 2
var my_pattern = new RegExp("([^?=&]+)(=([^&]*))?", "g");
query.replace(
  my_pattern,
  function($0, $1, $2, $3) {
    urlObj[$1] = $3;
  }
);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.