Skip to content

Instantly share code, notes, and snippets.

Created September 12, 2023 05:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Element Scan
function timedGet(selector) { let start =; let all = document.querySelectorAll(selector); let end =; return { start, end, all }; }
function iterateAll(selector, cb) {
let data = timedGet(selector);
for (let e of data.all) cb(e);
let end =;
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) {
for (let e of element.children) walk(e, cb);
function walkAll(cb) {
let start =;
walk(document.body, cb);
let end =;
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