url pathname

Benchmark created on


Setup

const url = "https://anonymous:flabada@developer.mozilla.org/en-US/docs/Web/API/URL/password?a=2#hhhhhh"

const fn = u => {
 let e = u.indexOf("?")
 if (e === -1) e = u.indexOf("#")
 if (e === -1) e = undefined
 return u.substring(u.indexOf("/", u.indexOf("/") + 2), e)
}

Test runner

Ready to run.

Testing in
TestOps/sec
URL
new URL(url).pathname
ready
regexp
url.match(/:\/\/.+?(\/[^?#]*)/)?.at(1) 
ready
fn
fn(url)
ready

Revisions

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