Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Partial base, search, fragment of URL 3
(version: 0)
Comparing performance of:
patern 1 vs patern 2 vs patern 3 vs patern 4 vs pattern 5
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var url1 = "https://localhost:3000/test?key1=value1&key2=value2#test"; 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) { const searchParamsIndex = inputUrl.indexOf('?'); const fragmentIndex = inputUrl.indexOf('#'); // 条件評価の結果を変数に格納 const hasSearchParams = searchParamsIndex !== -1; const hasFragment = fragmentIndex !== -1; const hasSearchParamsBeforeFragment = hasSearchParams && (!hasFragment || searchParamsIndex < fragmentIndex); let endOfUrlIndex = inputUrl.length; if (hasSearchParamsBeforeFragment) { endOfUrlIndex = searchParamsIndex; } else if (hasFragment) { endOfUrlIndex = fragmentIndex; } const url = inputUrl.substring(0, endOfUrlIndex); let searchParams = null; let fragmentText = null; if (hasFragment) { const fragmentWithQuery = inputUrl.substring(fragmentIndex + 1); const insideFragmentIndex = fragmentWithQuery.indexOf('?'); const hasInsideFragment = insideFragmentIndex !== -1; fragmentText = hasInsideFragment ? fragmentWithQuery.substring(0, insideFragmentIndex) : fragmentWithQuery; if (hasInsideFragment) { const fragmentSearchParams = fragmentWithQuery.substring(insideFragmentIndex + 1); searchParams = hasSearchParamsBeforeFragment ? inputUrl.substring(searchParamsIndex + 1, fragmentIndex) + '&' + fragmentSearchParams : fragmentSearchParams; } } if (hasSearchParamsBeforeFragment && !searchParams) { searchParams = hasFragment ? inputUrl.substring(searchParamsIndex + 1, fragmentIndex) : inputUrl.substring(searchParamsIndex + 1); } return { url, searchParams: searchParams || null, fragment: fragmentText || null }; } function extractParts5(inputUrl) { return new URL(inputUrl); }
Tests:
patern 1
extractParts1(url1);
patern 2
extractParts2(url1);
patern 3
extractParts3(url1);
patern 4
extractParts4(url1);
pattern 5
extractParts5(url1);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
patern 1
patern 2
patern 3
patern 4
pattern 5
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll provide an answer without asking any questions. Based on the provided benchmark results, it appears that there is some variation in the execution speed of the `extractParts` function across different test cases and browser versions. The functions are being tested on Chrome 116 with various inputs (urls) on a Mac OS X 10.15.7 desktop. Here's a summary of the findings: * Test case "patern 1" has the highest execution speed (10395294.0 executions per second). * Test case "patern 3" has a relatively fast execution speed (8372881.5 executions per second). * Test cases "patern 2", "patern 4", and "pattern 5" have lower execution speeds compared to the top two test cases. * There is some variation in execution speed across different browser versions, but it seems that Chrome 116 has a relatively consistent performance. To improve the performance of the `extractParts` function, you may want to consider optimizing the algorithm, reducing unnecessary computations, or leveraging browser-specific optimizations. However, without more context about the implementation of the function, it's difficult to provide specific suggestions for improvement.
Related benchmarks:
URL params
Check URL protocol and domain new URL, includes, endWith vs Regex
Partial base, search, fragment of URL
Partial base, search, fragment of URL 2
Comments
Confirm delete:
Do you really want to delete benchmark?