URL parse - Regex vs URL construct

Benchmark created on


Setup

const href = "https://www.prace.cz/nabidka/UP-29805040718/?rps=77&searchId=85294498-1717-4efd-85ad-5c69c1bc0697"

Test runner

Ready to run.

Testing in
TestOps/sec
Regexp
var reURLInformation = new RegExp([
    '^(https?:)//', // protocol
    '(([^:/?#]*)(?::([0-9]+))?)', // host (hostname and port)
    '(/{0,1}[^?#]*)', // pathname
    '(\\?[^#]*|)', // search
    '(#.*|)$' // hash
].join(''));
var match = href.match(reURLInformation);
console.log(match[2])
ready
URL constructor
var match = new URL(href).host;
console.log(match)
ready

Revisions

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