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
Jump 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
Test name
Executions per second
matches
23180166.0 Ops/sec
classList
25098942.0 Ops/sec
classList some
23640190.0 Ops/sec
Related benchmarks:
classList.contains vs.
classList.contains vs. loop vs regex
classList.contains vs. shorthand
Javascript classList.contains vs element.matches
Javascript classList.contains vs element.matches vs classList.some
hasAttribute vs classList
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?