Created
September 16, 2018 01:18
-
-
Save thysultan/41bb2fa096460f7a51cc38e127278af4 to your computer and use it in GitHub Desktop.
array-index elements.
This file contains hidden or 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
'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