Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Javascript classList.contains vs element.matches vs classList.some2
(version: 1)
Comparing performance of:
matches vs classList vs classList some
Created:
one year ago
by:
Guest
Go to the latest result
HTML Preparation code:
<body class="foo bar baz"></body>
Tests:
matches
var i = 1000; while (i--) { if (document.body.matches(".foo")) { return true; } }
classList
var i = 1000; while (i--) { if (document.body.classList.contains('foo')) { return true; } }
classList some
var i = 1000; while (i--) { if (['foo'].some(className => document.body.classList.contains(className))) { return true; } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
matches
classList
classList some
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
classList
25.1M/s
classList some
23.6M/s
matches
23.2M/s
View exact numbers
Test name
Executions per second
✓
classList
25,098,942 Ops/sec
classList some
23,640,190 Ops/sec
matches
23,180,166 Ops/sec
Related benchmarks
classList.contains vs.
classList.contains vs. loop vs regex
Javascript classList.contains vs element.matches
Javascript classList.contains vs element.matches vs classList.some
classList.contains vs. Set vs regex
Javascript classList.contains vs element.matches vs classList.some vs className
Javascript classList.contains vs element.matches vs classList.some vs classList.every
Comments
Confirm delete:
Do you really want to delete benchmark?