Find hostname from URL (v2)

Revision 2 of this benchmark created on


Setup

const url = 'https://www.example.com/lorem/ipsum/dolor?q=foo#example';

Test runner

Ready to run.

Testing in
TestOps/sec
Use regexp
const hostname = url.replace(/^https?\:\/+/, '').replace(/\/.+/, '');

console.log(hostname);
ready
Use URL object
const obj = new URL(url);
const hostname = obj.hostname;
console.log(hostname);
ready

Revisions

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