Skip to content

Instantly share code, notes, and snippets.

@natecavanaugh
Created July 20, 2012 23:57
Show Gist options
  • Save natecavanaugh/3153928 to your computer and use it in GitHub Desktop.
Save natecavanaugh/3153928 to your computer and use it in GitHub Desktop.
Alloy treeview performance test
var A = AUI();
var Lang = A.Lang;
var now = Lang.now;
var number_of_levels = 10;
var ts = now();
create_children = function(amount, level) {
amount = amount || 10;
if (level <= 3) {
return A.Array.map(new Array(amount).join('x').split('x'), function(n, i, c) {
var node = { label: 'test'+i };
if(level < 3 && (i % 4 === 0)){
node.children = create_children(amount, level + 1);
node.leaf = false;
node.expanded = true;
}
return node;
});
}
};
var objSize = function(arr) {
var size = arr.length;
A.each(
arr,
function(item, index, collection) {
if (item.children) {
size += objSize(item.children);
}
}
);
return size;
};
var cache = 1;
var children = cache && !Lang.isUndefined(children) ? children : create_children(number_of_levels, 0);
var times = !Lang.isUndefined(times) ? times : [];
if (times.length === 0) {
console.log('Number of children nodes: %d', objSize(children));
}
var start = now();
new A.TreeView({
label: 'ROOT',
id: 'root10',
expanded: true,
children: children
}).render();
var end = now();
var time = end - start;
times.push(time);
console.log('Current time: %d, all times: %a', time, times);
var timesLength = times.length;
if (timesLength === 3) {
var avg = A.Array.reduce(
times,
0,
function(prevVal, curVal, index, collection) {
return prevVal + curVal;
}
);
avg /= timesLength;
times.length = 0;
console.log('Average times across %d runs: %d ', timesLength, avg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment