Skip to content

Instantly share code, notes, and snippets.

@thysultan

thysultan/index.js

Created Sep 16, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.