Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Split vs new URL pathname
(version: 0)
Comparing performance of:
split vs pathname vs Split only using character
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var example = 'https://www.google.com/search?q=example+query+paramas+url&rlz=1C5CHFA_enGB926GB926&oq=example+query+paramas+url&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIICAEQABgWGB4yDQgCEAAYhgMYgAQYigUyDQgDEAAYhgMYgAQYigUyDQgEEAAYhgMYgAQYigUyDQgFEAAYhgMYgAQYigUyCggGEAAYogQYiQUyCggHEAAYogQYiQUyCggIEAAYgAQYogQyCggJEAAYgAQYogTSAQgzOTMxajBqN6gCALACAA&sourceid=chrome&ie=UTF-8'
Tests:
split
var result = example.split(/[?#]/)[0];
pathname
var result = new URL(example).pathname
Split only using character
var result = example.split('?')[0];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
split
pathname
Split only using character
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
split
3156567.5 Ops/sec
pathname
1097117.1 Ops/sec
Split only using character
12560949.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**What is being tested?** MeasureThat.net is testing the performance of two approaches to extract the URL path from a string: `split()` method with regular expressions (`/[#?]/`) and the `URL` constructor. The test cases are designed to compare the execution speed of these two methods, both using different types of character splitting (e.g., `/`, `#`, and `?`). **Options compared:** 1. **Split() method with regular expressions**: This approach uses the `split()` method with a regular expression that matches any of the characters `/`, `#`, or `?`. The resulting array is then indexed to extract the first element, which represents the URL path. 2. **URL constructor**: This approach uses the `URL` constructor, which creates a new `URL` object from a given string. The `pathname` property of this object contains the URL path. **Pros and cons:** * **Split() method with regular expressions**: + Pros: Can handle a wide range of URL formats, including those with special characters. + Cons: May be slower due to the overhead of regular expression compilation. * **URL constructor**: + Pros: Can be faster for simple URL paths and is generally considered more robust. + Cons: Requires the creation of an additional object, which may incur a slight performance penalty. **Other considerations:** * **Character splitting**: The test uses different types of character splitting (e.g., `/`, `#`, and `?`) to account for various URL formats. This is essential to ensure that both approaches perform well in different scenarios. * **Browser and device specifics**: The benchmark results include data on the browser, device platform, operating system, and executions per second. This information can help identify potential issues or optimizations specific to certain environments. **Library used:** In this test case, the `URL` constructor is using a built-in JavaScript library (the Web API). There is no additional external library required. **Special JS feature or syntax:** There are no special features or syntaxes used in this benchmark. The tests focus on comparing two fundamental approaches to URL path extraction. I hope this explanation helps! Let me know if you have any further questions.
Related benchmarks:
Slice/join vs Substr
Take last part from URL (Regex vs split)
split vs regex onurl
Split vs replace for url
Comments
Confirm delete:
Do you really want to delete benchmark?