Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0
Firefox 128
Windows
Desktop
5 months ago
Test name Executions per second
getAttribute 203902.8 Ops/sec
dataset 1136.4 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;
    }