Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
extract-root-domain
(version: 0)
extract-root-domain
Comparing performance of:
parseUri vs url_domain vs simple_domain vs url_class_hostname vs url_class_hostname2
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var link = "http://stackoverflow.com/questions/8498592/extract-root-domain-name-from-string"; var host; // parseUri 1.2.2 // (c) Steven Levithan <stevenlevithan.com> // MIT License function parseUri (str) { var o = parseUri.options, m = o.parser[o.strictMode ? "strict" : "loose"].exec(str), uri = {}, i = 14; while (i--) uri[o.key[i]] = m[i] || ""; uri[o.q.name] = {}; uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) { if ($1) uri[o.q.name][$1] = $2; }); return uri; }; parseUri.options = { strictMode: false, key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], q: { name: "queryKey", parser: /(?:^|&)([^&=]*)=?([^&]*)/g }, parser: { strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ } }; function url_domain(data) { var a = document.createElement('a'); a.href = data; return a.hostname; } function simple_domain(url) { var matches = url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i); return matches[1]; } function url_class_hostname(url) { return new URL(url).hostname; } var url2 = new URL("https://jsperf.com/"); function url_class_hostname2(url) {url2.href = url; return url2.hostname; }
Tests:
parseUri
host = parseUri(link).host;
url_domain
host = url_domain(link);
simple_domain
host = simple_domain(link);
url_class_hostname
var host = url_class_hostname(link);
url_class_hostname2
var host = url_class_hostname2(link);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
parseUri
url_domain
simple_domain
url_class_hostname
url_class_hostname2
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):
Let's dive into the world of MeasureThat.net and explore the JavaScript microbenchmarks. **Benchmark Definition Json** The benchmark definition json contains information about the benchmark itself, including its name, description, script preparation code, and HTML preparation code (which is null in this case). The script preparation code includes a set of functions to parse URLs: `parseUri`, `url_domain`, `simple_domain`, and `url_class_hostname`. These functions will be used to extract the root domain from a given URL. **Individual Test Cases** The individual test cases are defined in the "Test Name" field, which is repeated for each benchmark definition. Each test case has a unique name and a corresponding benchmark definition that extracts the host (root domain) from a specific URL using one of the four functions: `parseUri`, `url_domain`, `simple_domain`, or `url_class_hostname`. **Options Compared** The options compared in this benchmark are: 1. `parseUri` 2. `url_domain` 3. `simple_domain` 4. `url_class_hostname` Each of these functions uses a different approach to extract the root domain from a URL. **Pros and Cons of Each Approach** Here's a brief overview of each approach: 1. **`parseUri`**: This function uses the `uri` module (MIT License) to parse URLs. It is more flexible and handles edge cases well, but it may be slower due to its complexity. * Pros: Handles edge cases well, flexible * Cons: Slower, more complex 2. **`url_domain`**: This function uses the `a` element of a DOM object (`document.createElement('a')`) to parse URLs. It is simple and fast, but may not handle all edge cases. * Pros: Fast, simple * Cons: May not handle edge cases 3. **`simple_domain`**: This function extracts the host from a URL using string manipulation. It is very simple and fast, but may not handle edge cases well. * Pros: Very fast, simple * Cons: May not handle edge cases 4. **`url_class_hostname`**: This function uses the `window.location.hostname` property to extract the root domain from a URL. It is similar to `simple_domain`, but uses the browser's API instead of string manipulation. * Pros: Fast, simple * Cons: May not handle edge cases **Latest Benchmark Result** The latest benchmark result shows that: 1. `url_class_hostname` is the fastest (with an average execution time of 258.83 ms per second). 2. `simple_domain` is close behind, with an average execution time of 133.13 ms per second. 3. `parseUri` is slower than both of these options, with an average execution time of 358.29 ms per second. 4. `url_domain` is the slowest option, with an average execution time of 482.33 ms per second. Overall, this benchmark highlights the importance of choosing the right algorithm for extracting root domains from URLs, considering factors such as performance and edge case handling.
Related benchmarks:
Single function vs Multiple functions
isMarkdownURL
isMarkdownURL2
new Url vs host RegEx vs extractDomain lib
Comments
Confirm delete:
Do you really want to delete benchmark?