dataset vs getAttribute speed

JavaScript performance comparison

Test case created by shirokoff

Preparation code

<div id="testdiv" data-param="1"></div>
<script>
Benchmark.prototype.setup = function() {
    var div = document.getElementById("testdiv");
    div.setAttribute("data-param", "1")
};
</script>

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
getAttribute
var param = div.getAttribute("data-param");
div.setAttribute("data-param", param + 1);
pending…
dataset
var param = div.dataset.param;
div.dataset.param = param + 1;
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