Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Chrome 128
Linux
Desktop
4 months ago
Test name Executions per second
className 6404.0 Ops/sec
setAttribute 4516.2 Ops/sec
classList 3703.1 Ops/sec
HTML Preparation code:
AخA
 
1
<div id="foo"></div>
Script Preparation code:
 
var element = document.getElementById('foo');
Tests:
  • className

     
    var i = 1000;
    while (i--) {
        element.className = "bar";
    }
  • setAttribute

     
    var i = 1000;
    while (i--) {
        element.setAttribute("class", "bar");
    }
  • classList

     
    var i = 1000;
    while (i--) {
        element.classList.add("bar");
    }