Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Chrome 124
Windows
Desktop
8 months ago
Test name Executions per second
style.setProperty 16.1 Ops/sec
style.cssText 16.9 Ops/sec
style 14.4 Ops/sec
attributeStyleMap.set 4.6 Ops/sec
HTML Preparation code:
AخA
 
1
<div id="test"></div>
Script Preparation code:
 
el = document.getElementById("test");
Tests:
  • style.setProperty

    x
     
    let i = 0;
    while (i < 10000) {
      el.style.setProperty("color","red");
      el.style.setProperty("border","1vmin solid red");
      el.style.setProperty("padding","0.5vmin");
      el.style.setProperty("background-color","black");
      el.style.setProperty("height","1vh");
      el.style.setProperty("width","1vw");
      i++;
    }
  • style.cssText

     
    let i = 0;
    while (i < 10000) {
      el.style.cssText = "color:red;border:1vmin solid red;padding:0.5vmin;background-color:black;height:1vh;width:1vw;";
      i++;
    }
  • style

     
    let i = 0;
    while (i < 10000) {
      el.style = "color:red;border:1vmin solid red;padding:0.5vmin;background-color:black;height:1vh;width:1vw;";
      i++;
    }
  • attributeStyleMap.set

     
    let i = 0;
    while (i < 10000) {
      el.attributeStyleMap.set("color","red");
      el.attributeStyleMap.set("border","1vmin solid red");
      el.attributeStyleMap.set("padding","0.5vmin");
      el.attributeStyleMap.set("background-color","black");
      el.attributeStyleMap.set("height","1vh");
      el.attributeStyleMap.set("width","1vw");
      i++;
    }