Script Preparation code:
x
 
var notIns = document.createElement("div");
var notInsNested = document.createElement("div");
notIns.appendChild(notInsNested);
var ins = document.createElement("div");
var insNested = document.createElement("div");
ins.appendChild(insNested);
var body = document.body;
body.appendChild(ins);
var test = function(element) {
  var parentElement = element.parentElement;
  if(parentElement === null) {
   return false; 
  } else if(parentElement === body) {
    return true;
  }
  return test(parentElement);
};
Tests:
  • body.contains(); direct; notIns

     
    body.contains(notIns);
  • body.contains(); nested; notIns

     
    body.contains(notInsNested);
  • body.contains(); direct; ins

     
    body.contains(ins);
  • body.contains(); nested; ins

     
    body.contains(insNested);
  • own function; direct; notIns

     
    test(notIns);
  • own function; nested; notIns

     
    test(notInsNested);
  • own function; direct; ins

     
    test(ins);
  • own function; nested; ins

     
    test(insNested);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    body.contains(); direct; notIns
    body.contains(); nested; notIns
    body.contains(); direct; ins
    body.contains(); nested; ins
    own function; direct; notIns
    own function; nested; notIns
    own function; direct; ins
    own function; nested; ins

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 7 years ago)
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
Chrome 56 on Windows 7
View result in a separate tab
Test name Executions per second
body.contains(); direct; notIns 2600025.8 Ops/sec
body.contains(); nested; notIns 2634836.0 Ops/sec
body.contains(); direct; ins 2579353.0 Ops/sec
body.contains(); nested; ins 2574464.2 Ops/sec
own function; direct; notIns 3618504.0 Ops/sec
own function; nested; notIns 1767283.4 Ops/sec
own function; direct; ins 2546186.5 Ops/sec
own function; nested; ins 1499364.6 Ops/sec