Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
6 properties - style.setProperty vs style.cssText vs style vs Object.assign vs Object.entries with style.cssText vs setAttribute
(version: 0)
Comparing performance of:
style.setProperty vs style.cssText vs style vs Object.assign vs setAttribute vs Object.entries with style.cssText
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<div id="test"></div>
Script Preparation code:
el = document.getElementById("test");
Tests:
style.setProperty
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++; }
Object.entries with style.cssText
let style = { height: '1vh', width: '1vw', color: 'red', border: '1vmin solid red', backgroundColor: 'black', padding: '0.5vmin' }; let i = 0; while (i < 10000) { let cssText = Object.entries(style).reduce((acc, [key, value]) => { acc += `${key}: ${value};` return acc; }, ''); el.style.cssText = cssText; i++; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
style.setProperty
style.cssText
style
Object.assign
setAttribute
Object.entries with style.cssText
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
style➜display VS setAttribute➜display
6 properties - style.setProperty vs style.cssText vs style vs Object.assign vs setAttribute vs assign property
Setting CSS: Direct CSS property vs setAttribute("style",...)
Set Prop Varaible vs setAttribute
Set Prop Variable vs setAttribute
Comments
Confirm delete:
Do you really want to delete benchmark?