jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
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*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
}
};
var persistentAnchor = document.createElement('a');
function persistent_anchor(data) {
persistentAnchor.href = data;
return persistentAnchor.hostname;
}
// any_uri() would return empty string for "data:..." or
// whatever uri doesn't have a hostname in it. The extra
// IPv6 regex allows to not overcomplicate the first regex
// being used to extract hostname, hence it allows
// optimal performance when IPv6 addresses are rarely
// seen.
var any_uri = (function() {
var reAuthorityFromURI = /^(?:[^:\/?#]+:)?(\/\/[^\/?#]+)/;
var reHostFromAuthority = /^(?:[^@]+@)?([0-9a-z.-]+)(?::\d*)?$/i;
var reIPv6FromAuthority = /^(?:[^@]+@)?(\[[0-9a-f:]+\])(?::\d*)?$/i;
return function(uri) {
var matches = reAuthorityFromURI.exec(uri);
if (!matches) {
return '';
}
var authority = matches[1].slice(2);
matches = reHostFromAuthority.exec(authority);
if (!matches) {
matches = reIPv6FromAuthority.exec(authority);
if (!matches) {
return '';
}
}
return matches[1].toLowerCase();
};
})();
Ready to run.
Test | Ops/sec | |
---|---|---|
parseUri |
| ready |
anchor |
| ready |
any_hostname |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.