SVG attribute kebab-case conversion

Benchmark created on


Preparation HTML

<svg>
  <rect id="rect" width="100" height="100" stroke="red" />
</svg>

Setup

function toKebabCase(string) {
	    return string.replace(/[A-Z]/g, '-$&').toLowerCase();
	}

Test runner

Ready to run.

Testing in
TestOps/sec
to-kebab-case
for (let i = 0; i++; i < 100) {
  document.getElementById('rect').setAttribute(toKebabCase('strokeWidth'), i);
}
ready
to-kebab-case with cache
const strokeWidthAttribute = toKebabCase('strokeWidth')

for (let i = 0; i++; i < 100) {
  document.getElementById('rect').setAttribute(strokeWidthAttribute, i);
}
ready

Revisions

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