Skip to content

Instantly share code, notes, and snippets.

@wentout
Created October 13, 2020 21:05
Show Gist options
  • Select an option

  • Save wentout/1c857b77721663d82bad07ef2d89e899 to your computer and use it in GitHub Desktop.

Select an option

Save wentout/1c857b77721663d82bad07ef2d89e899 to your computer and use it in GitHub Desktop.
Prototype Chain Deepness test.
'use strict';
const MAX_NUM = 1000;
global.m = [];
global.start = Date.now();
global.current = {
name: 'root'
};
const makeNextEls = function () {
let name, el;
const pointer = global.current;
name = `idx_${ global.m.length }`;
el = {
name,
[name]: true,
parent: pointer,
get self () {
return el;
}
};
Object.setPrototypeOf(el, pointer);
global.current = el;
global.m.push(el);
if (global.m.length < MAX_NUM) {
console.log(global.m.length, name, (Date.now() - global.start) / 1000);
setTimeout(() => {
makeNextEls();
}, 0);
} else {
console.log('finished', global.m.length, (Date.now() - global.start) / 1000);
}
};
makeNextEls(global.current);
setInterval(() => {
console.log('ended');
}, 1000000);
debugger;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment