Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
classList.add vs setAttribute
Which is faster? Adding a class to an element of setting an attribute on it?
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0
Browser:
Firefox 130
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
setAttribute
9292315.0 Ops/sec
classList.add
4873082.5 Ops/sec
HTML Preparation code:
<div id="test">Testing</div>
Script Preparation code:
var el = document.getElementById('test');
Tests:
setAttribute
el.setAttribute('mytest', 'true')
classList.add
el.classList.add('mytest')