Find hostname from URL

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 hostname = url.replace(/^https?\:\/+/, '').replace(/\/.+/, '');

console.log(hostname);
ready

Revisions

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