Test name | Executions per second |
---|---|
style.setProperty | 27.9 Ops/sec |
style.cssText | 36.8 Ops/sec |
style replace | 32.8 Ops/sec |
Object.assign | 31.2 Ops/sec |
setAttribute | 33.0 Ops/sec |
style update | 25.9 Ops/sec |
style.cssText update | 12.7 Ops/sec |
<div id="test"></div>
el = document.getElementById("test");
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", i/100 + "%");
i++;
}
let i = 0;
while (i < 10000) {
el.style.cssText = `color:red;border:1vmin solid red;padding:0.5vmin;background-color:black;height:1vh;width:${i/100}%;`;
i++;
}
let i = 0;
while (i < 10000) {
el.style = `color:red;border:1vmin solid red;padding:0.5vmin;background-color:black;height:1vh;width:${i/100}%;`;
i++;
}
let i = 0;
while (i < 10000) {
Object.assign(el.style, {
height: '1vh',
width: i/100 + '%',
color: 'red',
border: '1vmin solid red',
backgroundColor: 'black',
padding: '0.5vmin'
});
i++;
}
let i = 0;
while (i < 10000) {
el.setAttribute('style',`color:red;border:1vmin solid red;padding:0.5vmin;background-color:black;height:1vh;width:${i/100}%;`);
i++;
}
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 = i/100 + "%";
i++;
}
let i = 0;
while (i < 10000) {
el.style.cssText += ';' + `color:red;border:1vmin solid red;padding:0.5vmin;background-color:black;height:1vh;width:${i/100}%;`;
i++;
}