Test thing (v2)

Revision 2 of this benchmark created on


Setup

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

const ATTRS_OBJ = URL_ATTRS.reduce((a, v) => ({ ...a, [v]: true}), {}) 

const ATTRS_MAP = new Map(URL_ATTRS.map((v) => [v, true]));

const re = RegExp('^(' + URL_ATTRS.join('|') + ')$')

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 hashmapBabyyyy(attrName) {
	return ATTRS_OBJ[attrName] ?? false;
}

function actualMap(attrName) {
	return ATTRS_MAP.get(attrName)?? false;
}

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
object
hashmapBabyyyy("url");
hashmapBabyyyy("src");
hashmapBabyyyy("href");
hashmapBabyyyy("asdf");
hashmapBabyyyy("zsdf");
ready
Actual map
actualMap("url");
actualMap("src");
actualMap("href");
actualMap("asdf");
actualMap("zsdf");
ready

Revisions

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