Test name | Executions per second |
---|---|
style.setProperty | 14.0 Ops/sec |
style.cssText | 12.5 Ops/sec |
style | 11.4 Ops/sec |
Object.assign | 12.8 Ops/sec |
setAttribute | 165.2 Ops/sec |
attributeStyleMap.set | 4.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","1vw");
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:1vw;";
i++;
}
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++;
}
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++;
}
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++;
}
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++;
}