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 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Mobile Safari/537.36
Browser:
Chrome Mobile 127
Operating system:
Android
Device Platform:
Mobile
Date tested:
one year ago
Test name
Executions per second
setAttribute
283911.2 Ops/sec
Object.assign
336006.7 Ops/sec
setAttributes
223566.8 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'});