forked from AmpersandJS/ampersand-filtered-subcollection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
performance.js
72 lines (64 loc) · 1.78 KB
/
performance.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*jshint node: true*/
var Collection = require('ampersand-collection');
var SubCollection = require('./ampersand-filtered-collection');
var State = require('ampersand-state');
var collectionSize = 10000;
//var collectionSize = 10;
var i = 0;
var names = ['Cat', 'Dog', 'Turtle', 'Dinosaur', 'Fish', 'Pony', 'Axolotl'];
var itemData = [];
var activeCounter = 0;
var Item = State.extend({
props: {
id: i,
name: 'string',
active: 'boolean'
}
});
var Items = Collection.extend({
model: Item,
comparator: 'name'
});
var items = new Items();
var activeItems = new SubCollection(items, {
filter: function (item) {
activeCounter++;
return item.active;
},
watched: ['active']
});
for (i = 0;i < collectionSize; i++) {
itemData.push({
id: i,
name: names[i % 5],
active: Boolean(i % 2), //Half active
});
}
//console.log('data', itemData);
console.time('using set all at once');
items.set(itemData);
console.timeEnd('using set all at once');
console.log('active ran', activeCounter, 'times');
console.log('items:', collectionSize);
console.log('active:', activeItems.length);
console.log('----------');
activeCounter = 0;
console.time('toggle half actives');
for (i = 0; i < collectionSize; i++) {
items.at(i).active = false;
}
console.timeEnd('toggle half actives');
console.log('active ran', activeCounter, 'times');
console.log('items:', collectionSize);
console.log('active:', activeItems.length);
console.log('----------');
activeCounter = 0;
console.time('toggle half actives');
for (i = 0; i < collectionSize; i++) {
items.at(i).active = true;
}
console.timeEnd('toggle half actives');
console.log('active ran', activeCounter, 'times');
console.log('items:', collectionSize);
console.log('active:', activeItems.length);
console.log('----------');