Test thing (v3)

Revision 3 of this benchmark created on


Setup

const URL_ATTRS = [
  'src',
  'url',
  'href',
  'action',
  'background',
  'cite',
  'icon',
  'manifest',
  'poster',
  'data',
  'codebase',
  'usemap',
  'longdesc',
  'profile',
];

const URL_ATTR_SET = new Set(URL_ATTRS);

const re = RegExp('\\b' + URL_ATTRS.join('\\b|\\b') + '\\b');


function isUrlAttr(attrName) {
  return URL_ATTRS.some(attr => attrName === attr);
}

function isRegexMatch(attrName) {
	return re.test(attrName);
}

function isUrlAttrIncludes(attrName) {
  return URL_ATTRS.includes(attrName);
}

function dumbLoop(attrName) {
	for (let i = 0; i< URL_ATTRS.length; i++) {
		if (URL_ATTRS[i] === attrName) {
			return true;
		}
	}
	return false;
}

function setHasUrl(attrName) {
	return URL_ATTR_SET.has(attrName);
}

Test runner

Ready to run.

Testing in
TestOps/sec
some
isUrlAttr("url");
isUrlAttr("src");
isUrlAttr("href");
isUrlAttr("asdf");
isUrlAttr("zsdf");

ready
regex
isRegexMatch("url");
isRegexMatch("src");
isRegexMatch("href");
isRegexMatch("asdf");
isRegexMatch("zsdf");
ready
includes
isUrlAttrIncludes("url");
isUrlAttrIncludes("src");
isUrlAttrIncludes("href");
isUrlAttrIncludes("asdf");
isUrlAttrIncludes("zsdf");
ready
dump loop
dumbLoop("url");
dumbLoop("src");
dumbLoop("href");
dumbLoop("asdf");
dumbLoop("zsdf");
ready
Set
setHasUrl("url");
setHasUrl("src");
setHasUrl("href");
setHasUrl("asdf");
setHasUrl("zsdf");
ready

Revisions

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