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++;
    }
  • Object.assign

     
    let style = {
      height: '1vh',
      width: '1vw',
      color: 'red',
      border: '1vmin solid red',
      backgroundColor: 'black',
      padding: '0.5vmin'
    };
    let i = 0;
    while (i < 10000) {
      Object.assign(el.style, style);
      i++;
    }
  • setAttribute

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

     
    let i = 0;
    while (i < 10000) {
      el.style.color = "red";
      el.style.border = "1vmin solid red";
      el.style.padding = "0.5vmin";
      el.style.backgroundColor = "black";
      el.style.height = "1vh";
      el.style.width = "1vw";
      i++;
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    style.setProperty
    style.cssText
    style
    Object.assign
    setAttribute
    Assign property

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 11 months ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:125.0) Gecko/20100101 Firefox/125.0
Firefox 125 on Mac OS X 10.15
View result in a separate tab
Test name Executions per second
style.setProperty 5.3 Ops/sec
style.cssText 15.7 Ops/sec
style 12.8 Ops/sec
Object.assign 4.6 Ops/sec
setAttribute 362.1 Ops/sec
Assign property 5.5 Ops/sec