Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
setAttribute vs Object.assign
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Browser:
Chrome 140
Operating system:
Linux
Device Platform:
Desktop
Date tested:
7 months ago
Test name
Executions per second
setAttribute
856245.1 Ops/sec
Object.assign
964526.1 Ops/sec
setAttributes
804644.1 Ops/sec
Tests:
setAttribute
var input = document.createElement("input"); input.setAttribute("class", "my-class"); input.setAttribute("type", "checkbox");
Object.assign
const input = document.createElement("input"); Object.assign(input, {class: 'my-class', type: 'checkbox'});
setAttributes
function setAttributes(el, attrs) {Object.keys(attrs).forEach(key => el.setAttribute(key, attrs[key]))} const input = document.createElement("input"); setAttributes(input, {class: 'my-class', type: 'checkbox'});