URL Parsing

JavaScript performance comparison

Revision 2 of this test case created by Kamran Ayub (@kamranayub)

Preparation code

<script src="https://cloud.github.com/downloads/medialize/URI.js/URI.min.js"></script>
      
<script>
Benchmark.prototype.setup = function() {
  var urlParseRE = /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/;
  var parser = document.createElement('a');
  var url = "http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content";

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Regex
var matches = urlParseRE.exec(url);
var hostname1 = matches[11];
var search1 = matches[16];
pending…
Native
parser.href = url;
var hostname2 = parser.hostname;
var search2 = parser.search;
pending…
URI.js
var uri = new URI(url);
var hostname3 = uri.hostname();
var search3 = uri.search();
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.

0 Comments