Created
December 11, 2015 08:50
-
-
Save edtoken/6b24e9950bca7d74a01b to your computer and use it in GitHub Desktop.
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
var text = ' Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'; | |
var _ = require('underscore'); | |
var div = document.getElementById('TEST'); | |
var count = 10000; | |
var parentsCount = 100; | |
var parentIds = _.range(0, parentsCount, 1); | |
var items = {}; | |
while (count > 0) { | |
var parentId = parentIds.pop() || 0; | |
items[count] = {p1: parentId} | |
count--; | |
} | |
var cache = {}; | |
var parents = {}; | |
var s = new Date(); | |
function add(key, parent) { | |
if (!cache[key]) { | |
cache[key] = { | |
item: document.createElement('div'), | |
parent: parent | |
}; | |
cache[key].item.id = key; | |
cache[key].item.appendChild(document.createTextNode(key + text)); | |
} | |
if (cache[cache[key].parent]) { | |
cache[cache[key].parent].item.appendChild(cache[key].item); | |
} | |
if (parent === 0) { | |
parents[key] = cache[key]; | |
} | |
}; | |
for (var n in items) { | |
add(n, items[n].p1); | |
} | |
var fragment = document.createDocumentFragment(); | |
for (var p in parents) { | |
fragment.appendChild(parents[p].item); | |
} | |
div.appendChild(fragment); | |
console.log(items); | |
console.log('READY:', new Date() - s, '.ms'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment