Modify element style vs add class in HTML element

Benchmark created on


Description

Test difference in javascript performance when modifying element style vs adding class to HTML element

Preparation HTML

<style>
.absolute{
	position:absolute;
}
</style>
<div id="add-position"></div>

Setup

const addPosition = document.getElementById("add-position")

Test runner

Ready to run.

Testing in
TestOps/sec
Add class in HTML element
addPosition.classList.add("absolute")
ready
Modify element style
addPosition.style.position = "absolute"
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.