Run details:
Mozilla/5.0 (Linux; Android 10; SAMSUNG SM-N986N) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/23.0 Chrome/115.0.0.0 Mobile Safari/537.36
Chrome Mobile 115
Android
Mobile
one year ago
Test name Executions per second
Contains 4273268.5 Ops/sec
Closest 4389137.5 Ops/sec
HTML Preparation code:
AخA
 
1
<div class="parent">
2
  <div class="child">
3
    </div>
4
</div>
Script Preparation code:
 
var parent = document.querySelector(".parent");
var child = document.querySelector(".child");
Tests:
  • Contains

    x
     
    var x = parent.contains(child)
  • Closest

     
    var x = child.closest('.parent')