set attribute

JavaScript performance comparison

Test case created by clshortfuse

Preparation code

<div id="1" dir="ltr"/>
      
<script>
Benchmark.prototype.setup = function() {
  const el = document.getElementById('1');

};

Benchmark.prototype.teardown = function() {
  el.attributes.dir.nodeValue = 'rtl';

};
</script>

Preparation code output

<div id="1" dir="ltr"/>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
setAttribute
el.setAttribute('dir', 'rtl');
pending…
.dir
el.dir = 'rtl';
pending…
['dir']
el["dir"] = 'rtl';
pending…
attributes.getNamedItem
el.attributes.getNamedItem('dir').nodeValue = 'rtl';
pending…
attributes.dir
el.attributes.dir.nodeValue = 'rtl';
pending…
attributes['dir']
el.attributes['dir'].nodeValue = 'rtl';
pending…
setNamedItem
let newAttr = document.createAttribute('dir');
newAttr.nodeValue = 'rtl';
el.attributes.setNamedItem(newAttr);
pending…
.attributes['dir'] =
let newAttr = document.createAttribute('dir');
newAttr.nodeValue = 'rtl';
el.attributes['dir'] = newAttr;
pending…
.attributes.dir =
let newAttr = document.createAttribute('dir');
newAttr.nodeValue = 'rtl';
el.attributes.dir = newAttr;
pending…
.customPropertyDir
el.customPropertyDir = 'rtl';
pending…

Compare results of other browsers

Revisions

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

0 Comments