Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
matches vs. closest vs. classList (with element tag check) 2
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
matches
3927.6 Ops/sec
closest
3498.2 Ops/sec
classList (with nodeName)
2303.1 Ops/sec
classList (with tagName)
2072.3 Ops/sec
classList (with instanceof)
1506.6 Ops/sec
HTML Preparation code:
<div class="foo"></div>
Tests:
matches
var element = document.querySelector(".foo"); var i = 1000; while (i--) { if (!element.matches("div.foo")) { throw new Error("check failed"); } }
closest
var element = document.querySelector(".foo"); var i = 1000; while (i--) { if (!element.closest("div.foo")) { throw new Error("check failed"); } }
classList (with nodeName)
var element = document.querySelector(".foo"); var i = 1000; while (i--) { if (!(element.nodeName === "DIV" && element.classList.contains("foo"))) { throw new Error("check failed"); } }
classList (with tagName)
var element = document.querySelector(".foo"); var i = 1000; var className = "foo"; while (i--) { if (!(element.tagName === "DIV" && element.classList.contains("foo"))) { throw new Error("check failed"); } }
classList (with instanceof)
var element = document.querySelector(".foo"); var i = 1000; while (i--) { if (!(element instanceof HTMLDivElement && element.classList.contains("foo"))) { throw new Error("check failed"); } }