Comparison of replacing a class with className, classList.replace and setAttribute (version: 0)
Compares performance of changing the class name through one of the following three interfaces:
- Element.className
- Element.classList.replace
- Element.setAttribute
Inspiration originates from "Avoiding the FOUC v3.0": https://www.paulirish.com/2009/avoiding-the-fouc-v3/
Preparation code is based on this test: https://measurethat.net/Benchmarks/Show/54/0/classname-vs-setattribute-vs-classlist
Comparing performance of: Element.className vs Element.classList vs Element.setAttribute
Memory measurements supported only in Chrome.
For precise memory measurements Chrome must be launched with --enable-precise-memory-info flag.
More information: Monitoring JavaScript Memory
Test case name
Result
Element.className
Element.classList
Element.setAttribute
Fastest:N/A
Slowest:N/A
Latest run results:
Run details: (Test run date:
5 months ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36