hasWWW vs stripWWW

Benchmark created on


Setup

const stripWWW = (domain) => domain.replace(/^www\./, '');
const stripWWW2 = (domain) => hasWWW(domain) ? domain.slice(4) : domain;
const hasWWW = (value) => value.startsWith('www.');
const hasSubdomain = (value) => value.split('.').length > (hasWWW(value) ? 3 : 2);
const hasSubdomain2 = (value) => stripWWW(value).split('.').length > 2;
const hasSubdomain3 = (value) => stripWWW2(value).split('.').length > 2;

const urls = [
   'www.test.cz',
   'test.cz',
   'sub.test.cz'
];

Test runner

Ready to run.

Testing in
TestOps/sec
hasSubdomain - hasWWW
urls.forEach((url) => hasSubdomain(url));
ready
hasSubdomain - stripWWW regexp
urls.forEach((url) => hasSubdomain2(url));
ready
hasSubdomain - stripWWW slice
urls.forEach((url) => hasSubdomain3(url));
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.