Test name | Executions per second |
---|---|
elementFromPoint 1K | 542.2 Ops/sec |
elementFromPoint 10K | 45.5 Ops/sec |
elementFromPoint 100K | 9.0 Ops/sec |
elementFromPoint 1M | 2.3 Ops/sec |
<style>
#container {
width: 1000px;
height: 1000px;
}
#container * {
display: flex;
flex: 1 1;
background: red;
border: 1px solid black;
min-width: 0;
min-height: 0;
width: 100%;
height: 100%;
}
#container .tick {
flex-direction: row;
}
#container .tock {
flex-direction: column;
}
</style>
<div id="container"></div>
const container = document.getElementById("container");
const depth = 12;
const childrenPerLevel = 3;
/**
* @param {HTMLElement} parent
* @param {boolean} isTick
*/
const addElement = (parent, isTick) => {
const el = document.createElement("div");
el.classList.add(isTick ? "tick" : "tock");
parent.appendChild(el);
return el;
};
let currLevel = [container];
let nextLevel = [];
for (let i = 0; i < depth; i++) {
for (const parent of currLevel) {
for (let j = 0; j < childrenPerLevel; j++) {
nextLevel.push(addElement(parent, i % 2 === 0));
}
}
currLevel = nextLevel;
nextLevel = [];
}
const n = 1_000;
const nsq = Math.floor(Math.sqrt(n));
const arr = Array(n).fill(0).map((v,i)=>i);
arr.map((v,i)=>document.elementFromPoint(i%nsq, Math.floor(i/nsq)));
const n = 10_000;
const nsq = Math.floor(Math.sqrt(n));
const arr = Array(n).fill(0).map((v,i)=>i);
arr.map((v,i)=>document.elementFromPoint(i%nsq, Math.floor(i/nsq)));
const n = 100_000;
const nsq = Math.floor(Math.sqrt(n));
const arr = Array(n).fill(0).map((v,i)=>i);
arr.map((v,i)=>document.elementFromPoint(i%nsq, Math.floor(i/nsq)));
const n = 1_000_000;
const nsq = Math.floor(Math.sqrt(n));
const arr = Array(n).fill(0).map((v,i)=>i);
arr.map((v,i)=>document.elementFromPoint(i%nsq, Math.floor(i/nsq)));