hostname from url (v23)

Revision 23 of this benchmark created by BobSmith on


Setup

var link = "http://stackoverflow.com/questions/8498592/extract-root-domain-name-from-string";
  var host;
  
  function simple_domain(url)
  {
  var matches = url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);
  return matches[1];
  }
  
  function simple_domain_2(url2)
  {
  var matches2 = url2.match(/(?:[\w-]+\.)+[\w-]+/);
  return matches2[1];
  }
  
  function simple_domain_3(url3)
  {
  var urlParts = url3.split(/[/?#]/);
  return urlParts[0];
  }

Test runner

Ready to run.

Testing in
TestOps/sec
parseUri
host = simple_domain_3(link);
ready
anchor
host = simple_domain_2(link);
ready
simpledomain
host = simple_domain(link);
ready

Revisions

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