Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
Chrome 114
Windows
Desktop
one year ago
Test name Executions per second
getAttribute 2405.5 Ops/sec
dataset 1015.2 Ops/sec
HTML Preparation code:
AخA
 
1
<div id="foo" data-foo="foo_id"></div>
Tests:
  • getAttribute

     
    var element = document.getElementById("foo");
    var i = 10000;
    while (i--) {
        var foo = element.getAttribute("data-foo");
    }
  • dataset

     
    var element = document.getElementById("foo");
    var i = 10000;
    while (i--) {
        var foo = element.dataset.foo;
    }