SVG setAttribute/baseVal as number/string (v3)

Revision 3 of this benchmark created by Alexis Deveria on


Preparation HTML

<script>
  var ns = "http://www.w3.org/2000/svg";
  var svg = document.createElementNS(ns, 'svg');
  document.body.appendChild(svg);
  var r1 = document.createElementNS(ns, 'rect');
  r1.setAttribute('height', 53);
  r1.setAttribute('width', 69);
  r1.setAttribute('y', 31);
  r1.setAttribute('x', 77);
  r1.setAttribute('stroke', '#000000');
  r1.setAttribute('fill', '#007fff');
  svg.appendChild(r1);
  
  var r1width_attr = r1.attributes[1];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
setAttribute number
r1.setAttribute('width', 42);
ready
setAttribute string
r1.setAttribute('width', '42');
ready
set baseVal number
r1.width.baseVal.value = 42;
ready
set baseVal string
r1.width.baseVal.value = "42";
ready
set attr value number
r1width_attr.value = 42;
ready
set attr value string
r1width_attr.value = "42";
ready
set attr nodeValue number
r1width_attr.nodeValue = 42;
ready
set attr nodeValue string
r1width_attr.nodeValue = "42";
ready
setAttributeNS number
r1.setAttributeNS(null, 'width', 42);
ready
setAttributeNS string
r1.setAttributeNS(null, 'width', "42");
ready

Revisions

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

  • Revision 1: published by Alexis Deveria on
  • Revision 2: published by Alexis Deveria on
  • Revision 3: published by Alexis Deveria on
  • Revision 6: published on