Extract hostname Angular element vs Regex (v2)

Revision 2 of this benchmark created by Guntars on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.13/angular.min.js"></script>

Setup

var testUrl = "http://www.zingertown.com/moo/moo?shaka=1&laka=3"
    
      function hostnameAngularElement(url) {
        return angular.element("<a href='" + url + "' />")[0].hostname
      }
    
      function hostnameRegex(url) {
        return url.match(/https?:\/\/([^/]+)/)[1]
      }

Test runner

Ready to run.

Testing in
TestOps/sec
Angular element
hostnameAngularElement(testUrl)
ready
Regex
hostnameRegex(testUrl)
ready

Revisions

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

  • Revision 2: published by Guntars on