dataattribute vs setAttribute

JavaScript performance comparison

Test case created by Fellyph Cintra

Info

Compare data attribute with setAttribute

Preparation code

<body>
 <div data-key="5"></div>
</body>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
com data set
var elemento = document.getElementsByTagName("div")[0] 
var key = elemento.dataset.key;
elemento.dataset.language = "HTML" + key;
 
 
pending…
com getAttribute
var elemento = document.getElementsByTagName("div")[0] 
var key = elemento.getAttribute("data-key");
elemento.setAttribute("data-language", "HTML" + key);
 
pending…

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

Compare results of other browsers

0 comments

Add a comment