Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Partial base, search, fragment of URL
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Browser:
Chrome 122
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
patern 1
3962282.8 Ops/sec
patern 2
4557349.5 Ops/sec
patern 3
5784386.0 Ops/sec
patern 4
901886.6 Ops/sec
Script Preparation code:
var url1 = "https://localhost:3000/test?key1=value1&key2=value2#test"; var url2 = "https://localhost:3000/test#test?key1=value1&key2=value2"; const urlPattern = /^(https?:\/\/[^\/?#]+[^?#]*)?(?:\?([^#]*))?(?:#([^?]*))?(?:\?([^#]*))?/; function extractParts1(inputUrl) { const match = inputUrl.match(urlPattern); if (!match) return null; let url = match[1] || null; let searchParams = match[2] || null; let fragment = match[3] || null; // If there are query parameters after the fragment if (match[4]) { searchParams = searchParams ? searchParams + '&' + match[4] : match[4]; } return { url, searchParams, fragment }; } function extractParts2(inputUrl) { // Parse basic URL and fragment const [base, fragmentQuery] = inputUrl.split('#'); // Parse URL and search parameters from base let [url, searchParams] = base.split('?'); // If there's fragment data, check for additional query parameters let fragment = null; let extraSearchParams = null; if (fragmentQuery) { if (fragmentQuery.includes('?')) { [fragment, extraSearchParams] = fragmentQuery.split('?'); searchParams = searchParams ? `${searchParams}&${extraSearchParams}` : extraSearchParams; } else { fragment = fragmentQuery; } } return { url, searchParams: searchParams || null, fragment: fragment || null }; } function extractParts3(inputUrl) { const queryIndex = inputUrl.indexOf('?'); const hashIndex = inputUrl.indexOf('#'); const hasQueryBeforeHash = queryIndex !== -1 && (hashIndex === -1 || queryIndex < hashIndex); const url = hasQueryBeforeHash ? inputUrl.substring(0, queryIndex) : (hashIndex !== -1 ? inputUrl.substring(0, hashIndex) : inputUrl); let searchParams = null, fragment = null; if (hashIndex !== -1) { const fragmentWithQuery = inputUrl.substring(hashIndex + 1); const fragmentQueryIndex = fragmentWithQuery.indexOf('?'); if (fragmentQueryIndex !== -1) { fragment = fragmentWithQuery.substring(0, fragmentQueryIndex); searchParams = fragmentWithQuery.substring(fragmentQueryIndex + 1); if (hasQueryBeforeHash) { searchParams = inputUrl.substring(queryIndex + 1, hashIndex) + '&' + searchParams; } } else { fragment = fragmentWithQuery; } } if (hasQueryBeforeHash && !searchParams) { searchParams = hashIndex !== -1 ? inputUrl.substring(queryIndex + 1, hashIndex) : inputUrl.substring(queryIndex + 1); } return { url, searchParams: searchParams || null, fragment: fragment || null }; } function extractParts4(inputUrl) { return new URL(inputUrl); }
Tests:
patern 1
extractParts1(url1); extractParts1(url2);
patern 2
extractParts2(url1); extractParts2(url2);
patern 3
extractParts3(url1); extractParts3(url2);
patern 4
extractParts4(url1); extractParts4(url2);