Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Chrome 133
Windows
Desktop
one month ago
Test name Executions per second
setAttribute 311.7 Ops/sec
style 336.2 Ops/sec
HTML Preparation code:
AخA
 
1
<div id="foo"></div>
Script Preparation code:
 
var element = document.getElementById("foo");
const array = new Array(10000);
for (var i = 0; i < array.length; i++) {
    array[i] = `width: ${i}px; height: ${i}px;`
}
Tests:
  • setAttribute

     
    for (var i = 0; i < array.length; i++) {
        element.setAttribute("style", array[i]);
    }
  • style

     
    for (var i = 0; i < array.length; i++) {
        element.style.cssText = array[i];
    }