Element Scan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function timedGet(selector) { let start = performance.now(); let all = document.querySelectorAll(selector); let end = performance.now(); return { start, end, all }; } | |
function iterateAll(selector, cb) { | |
let data = timedGet(selector); | |
for (let e of data.all) cb(e); | |
let end = performance.now(); | |
console.log({ start: data.start, iter: data.end, end, duration: end - data.start }) | |
} | |
seen2 = new Set(); iterateAll('*', (e) => seen2.add(e)); | |
function walk(element, cb) { | |
cb(element); | |
for (let e of element.children) walk(e, cb); | |
} | |
function walkAll(cb) { | |
let start = performance.now(); | |
walk(document.body, cb); | |
let end = performance.now(); | |
console.log({ start, end, duration: end - start }); | |
} | |
seen = new Set(); walkAll((e) => seen.add(e)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment