Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
new Url vs RegEx (1)
(version: 0)
Comparing performance of:
new URL vs RegEx
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
new URL
return new URL('https://is5-ssl.mzstatic.com/image/thumb/Purple126/v4/00/33/2e/00332e58-b196-82cf-1231-82d81d6fe477/AppIcon_TikTok-0-0-1x_U007emarketing-0-0-0-7-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/512x0w.png').origin;
RegEx
return 'https://is5-ssl.mzstatic.com/image/thumb/Purple126/v4/00/33/2e/00332e58-b196-82cf-1231-82d81d6fe477/AppIcon_TikTok-0-0-1x_U007emarketing-0-0-0-7-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/512x0w.png'.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n?]+)(\/[^?#]*)?(\?[^#]*)?/)[0]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
new URL
RegEx
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Browser/OS:
Chrome 125 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
new URL
1107430.2 Ops/sec
RegEx
1324442.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
The provided benchmark measures the performance difference between two approaches to parse URLs in JavaScript: 1. **new URL()**: This method is part of the URL API, introduced in ECMAScript 2016 (ES6). It creates a new URL object from a given string, parsing it according to the URL syntax rules. 2. **Regular Expression (RegEx)**: The benchmark uses a RegEx pattern to extract the URL components from a given string. **Options compared:** * `new URL()` * Regular Expression (RegEx) **Pros and Cons of each approach:** 1. **new URL():** * Pros: + More readable and maintainable code, as it uses an object-oriented interface. + Less error-prone, as the API is well-defined and easy to use. + Supports more advanced URL features, such as parsing query parameters and fragment identifiers. * Cons: + May be slower than RegEx for simple cases, due to the overhead of creating a new object. 2. **Regular Expression (RegEx):** * Pros: + Highly optimized for performance, as it uses native engine capabilities. + Can be faster than `new URL()` for very simple URL parsing cases. * Cons: + Less readable and maintainable code, due to the complex pattern syntax. + Error-prone, as a single mistake can lead to unexpected results. **Library usage:** None of the benchmarks uses any external libraries beyond JavaScript's built-in functionality (e.g., `URL` API). **Special JS features or syntax:** The benchmark does not use any special JavaScript features or syntax. However, it does use ECMAScript 2016 (ES6) syntax for the `new URL()` method. **Alternatives:** For simple URL parsing cases, RegEx might be sufficient and more efficient than `new URL()`. For more complex URL parsing needs, `new URL()` is likely a better choice due to its object-oriented interface and support for advanced features. Other alternatives for comparing URL parsing performance include: * Using a library like [url-regex](https://github.com/sindresorhus/url-regex) or [url-normalizer](https://github.com/matteowiesler/url-normalizer), which provide optimized RegEx patterns for common URL use cases. * Implementing custom URL parsing logic using a combination of JavaScript and native code (e.g., C++ or Assembly). * Using a third-party benchmarking library like [benchmark.js](https://github.com/GoogleChrome/benchmark) to run multiple benchmarks simultaneously.
Related benchmarks:
Take last part from URL (Regex vs split)
split vs regex onurl
regecxt
regecxgth
Regex vs URL
Comments
Confirm delete:
Do you really want to delete benchmark?