Modify element style vs add class in HTML element (v2)

Revision 2 of this 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
Modify element style
addPosition.style.position = "absolute"
ready
Add class in HTML element
addPosition.classList.add("absolute")
ready

Revisions

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