Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
className.includes vs. classList.contains vs matches
(version: 1)
Comparing performance of:
className vs classList vs matches
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<div id="foo" class="test"></div>
Tests:
className
var element = document.getElementById("foo"); var i = 1000; while (i--) { if (element.className.includes("test")) {} }
classList
var element = document.getElementById("foo"); var i = 1000; while (i--) { element.classList.contains("test"); }
matches
var element = document.getElementById("foo"); var i = 1000; while (i--) { element.matches(".test"); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
className
classList
matches
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
16 days ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0
Browser/OS:
Firefox 140 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
className
1701251.9 Ops/sec
classList
1709648.0 Ops/sec
matches
23019.4 Ops/sec
Related benchmarks:
className.indexOf vs. classList.contains
JavaScript className.indexOf vs. classList.contains
className.indexOf vs. classList.contains (fixed)
classList.contains VS className.includes
classList.contains VS className.includes 1000
className.includes vs. classList.contains
className.indexOf vs. classList.contains2
boolean flag vs. classList.contains
classList.contains VS dataset
Comments
Confirm delete:
Do you really want to delete benchmark?