svg search

Benchmark created on


Setup

const nonTextSvgTagNames = [
  // 'a',
  'altGlyph',
  'altGlyphDef',
  'altGlyphItem',
  'animate',
  'animateColor',
  'animateMotion',
  'animateTransform',
  'animation',
  'audio',
  'canvas',
  'circle',
  'clipPath',
  'color-profile',
  'cursor',
  'defs',
  // 'desc',
  'discard',
  'ellipse',
  'feBlend',
  'feColorMatrix',
  'feComponentTransfer',
  'feComposite',
  'feConvolveMatrix',
  'feDiffuseLighting',
  'feDisplacementMap',
  'feDistantLight',
  'feDropShadow',
  'feFlood',
  'feFuncA',
  'feFuncB',
  'feFuncG',
  'feFuncR',
  'feGaussianBlur',
  'feImage',
  'feMerge',
  'feMergeNode',
  'feMorphology',
  'feOffset',
  'fePointLight',
  'feSpecularLighting',
  'feSpotLight',
  'feTile',
  'feTurbulence',
  'filter',
  'font',
  'font-face',
  'font-face-format',
  'font-face-name',
  'font-face-src',
  'font-face-uri',
  'foreignObject',
  'g',
  'glyph',
  'glyphRef',
  'handler',
  'hkern',
  'iframe',
  'image',
  'line',
  'linearGradient',
  'listener',
  'marker',
  'mask',
  'metadata',
  'missing-glyph',
  'mpath',
  'path',
  'pattern',
  'polygon',
  'polyline',
  'prefetch',
  'radialGradient',
  'rect',
  'script',
  'set',
  'solidColor',
  'stop',
  'style',
  'svg',
  'switch',
  'symbol',
  'tbreak',
  // 'text',
  // 'textArea',
  'textPath',
  // 'title',
  'tref',
  // 'tspan',
  'unknown',
  'use',
  'video',
  'view',
  'vkern'
]
nonTextSvgTagNamesObj = Object.fromEntries(nonTextSvgTagNames.map(n => [n, true]));
const entries = Array.from({length: 10_000}, (v, i) => nonTextSvgTagNames[i % nonTextSvgTagNames.length])

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf
function isSvgIO(tag) {
	return nonTextSvgTagNames.indexOf(tag) !== -1; 
}
entries.forEach(isSvgIO)
ready
hash
function isSvgH(tag) {
	return !!nonTextSvgTagNamesObj[tag]; 
}
entries.forEach(isSvgH)
ready

Revisions

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