Skip to content

Instantly share code, notes, and snippets.

@thysultan
Created September 16, 2018 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thysultan/41bb2fa096460f7a51cc38e127278af4 to your computer and use it in GitHub Desktop.
Save thysultan/41bb2fa096460f7a51cc38e127278af4 to your computer and use it in GitHub Desktop.
array-index elements.
'use strict'
var h1 = function (tag, props, children) {
return {tag: tag, props: props, children: children}
}
var h2 = function (tag, props, children) {
return {tag: tag, props: props, children: children, 9: ''}
}
var start, end;
var iter = 500000;
var nodes1 = []
var nodes2 = []
{
start = Date.now()
for (var i = 0; i < iter; ++i) {
var node = h1('h'+i, {i}, ['index: ', i]);
node.tag = 'i:' + (i + 1)
if (node.tag === undefined) {
throw 'failed!'
}
nodes1.push(node);
}
console.log('0', Date.now() - start)
}
{
start = Date.now()
for (var i = 0; i < iter; ++i) {
var node = h2('h'+i, {i}, ['index: ', i]);
node[2] = 'i:' + (i + 1)
if (node[2] === undefined) {
throw 'failed!'
}
nodes2.push(node);
}
console.log('1', Date.now() - start)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment