Hostname from url

JavaScript performance comparison

Test case created by Mijahn

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var URL = "http://example.com/somepages.html";
  var host;
  
  function hostFromMatch(url) {
    var matches = url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);
    return matches[1];
  }
  
  function hostFromDomElement(url) {
    var parser = document.createElement('a');
    parser.href = url;
    return parser.hostname;
  }

};
</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
hostFromMatch
hostFromMatch(URL);
pending…
hostFromDomElement
hostFromDomElement(URL);
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