RegExp vs Url for get path

Benchmark created on


Setup

const url = 'https://any.d.site.com/edit/d/E5WneXf9rZtgJA'

Test runner

Ready to run.

Testing in
TestOps/sec
RegExp
const path = url.match(/^https?:\/\/[A-Za-z0-9:.]*([\/]{1}.*\/?)$/)[1]
ready
Url
const path = new URL(url).pathname
ready
URL.parse
const path = URL.parse(url).pathname
ready

Revisions

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