Test name | Executions per second |
---|---|
style.setProperty | 472450.4 Ops/sec |
style.cssText | 568467.8 Ops/sec |
style | 500901.4 Ops/sec |
attributeStyleMap.set | 192396.1 Ops/sec |
<div id="test"></div>
el = document.getElementById("test");
style = el.style
attributeStyleMap = el.attributeStyleMap
color = 'red'
border = '1vmin solid red'
padding = '.5vmin'
backgroundColor = 'black'
height = '1vh'
width = '1vw'
style.setProperty("color", color);
style.setProperty("border", border);
style.setProperty("padding", padding);
style.setProperty("background-color", backgroundColor);
style.setProperty("height", height);
style.setProperty("width", width);
style.cssText = `color:${color};border:${border};padding:${padding};background-color:${backgroundColor};height:${height};width:${width};`;
el.style = `color:${color};border:${border};padding:${padding};background-color:${backgroundColor};height:${height};width:${width};`;
attributeStyleMap.set("color",color);
attributeStyleMap.set("border",border);
attributeStyleMap.set("padding",padding);
attributeStyleMap.set("background-color",backgroundColor);
attributeStyleMap.set("height",height);
attributeStyleMap.set("width",width);