mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 21:17:03 +00:00
Performance test array controller addObject: when clearing the filter predicate.
This commit is contained in:
@@ -2,16 +2,17 @@
|
||||
@import <Foundation/CPPredicate.j>
|
||||
@import <AppKit/CPArrayController.j>
|
||||
|
||||
var ELEMENTS = 200,
|
||||
REPEATS = 25;
|
||||
|
||||
@implementation CPArrayControllerPerformance : OJTestCase
|
||||
|
||||
- (void)testRearrangeObjects
|
||||
- (CPArrayController)setupWithElements:(int)aCount
|
||||
{
|
||||
var ELEMENTS = 200,
|
||||
REPEATS = 25,
|
||||
ac = [CPArrayController new],
|
||||
var ac = [CPArrayController new],
|
||||
array = [];
|
||||
|
||||
for (var i = 0; i < ELEMENTS; i++)
|
||||
for (var i = 0; i < aCount; i++)
|
||||
{
|
||||
var s = [Sortable new];
|
||||
[s setA:i];
|
||||
@@ -19,15 +20,17 @@
|
||||
array.push(s);
|
||||
}
|
||||
|
||||
var descriptors = [
|
||||
[CPSortDescriptor sortDescriptorWithKey:"a" ascending:NO],
|
||||
];
|
||||
|
||||
[ac setContent:array];
|
||||
|
||||
|
||||
[ac setFilterPredicate:[CPPredicate predicateWithFormat:@"(b != %@)", 0]];
|
||||
|
||||
return ac;
|
||||
}
|
||||
|
||||
- (void)testRearrangeObjects
|
||||
{
|
||||
var ac = [self setupWithElements:ELEMENTS];
|
||||
|
||||
// Filter alone
|
||||
var start = (new Date).getTime();
|
||||
for (var i = 0; i < REPEATS; i++)
|
||||
@@ -41,7 +44,7 @@
|
||||
for (var j = 0, count = [sorted count]; j < count; j++)
|
||||
{
|
||||
if (sorted[j].b == 0)
|
||||
[self fail:"b == 0 should be filtered out (position: "+j+")"];
|
||||
[self fail:"b == 0 should be filtered out (position: " + j + ")"];
|
||||
last = sorted[j];
|
||||
}
|
||||
}
|
||||
@@ -49,7 +52,9 @@
|
||||
|
||||
CPLog.warn("testRearrangeObjects, filter: "+(end-start)+"ms");
|
||||
|
||||
[ac setSortDescriptors:descriptors];
|
||||
[ac setSortDescriptors:[
|
||||
[CPSortDescriptor sortDescriptorWithKey:"a" ascending:NO],
|
||||
]];
|
||||
|
||||
// Filter and sort.
|
||||
start = (new Date).getTime();
|
||||
@@ -64,9 +69,9 @@
|
||||
for (var j = 0, count = [sorted count]; j < count; j++)
|
||||
{
|
||||
if (sorted[j].b == 0)
|
||||
[self fail:"b == 0 should be filtered out (position: "+j+")"];
|
||||
[self fail:"b == 0 should be filtered out (position: " + j + ")"];
|
||||
if (sorted[j].a >= last)
|
||||
[self fail:"array values should be descending (position: "+j+")"];
|
||||
[self fail:"array values should be descending (position: " + j + ")"];
|
||||
last = sorted[j];
|
||||
}
|
||||
}
|
||||
@@ -75,6 +80,40 @@
|
||||
CPLog.warn("testRearrangeObjects, filter and sort: "+(end-start)+"ms");
|
||||
}
|
||||
|
||||
- (void)testAddObject_
|
||||
{
|
||||
var ac = [self setupWithElements:ELEMENTS],
|
||||
predicate = [ac filterPredicate],
|
||||
content = [[ac content] copy];
|
||||
|
||||
// Add object while clearing the predicate.
|
||||
[ac setClearsFilterPredicateOnInsertion:YES];
|
||||
|
||||
[ac setSortDescriptors:[
|
||||
[CPSortDescriptor sortDescriptorWithKey:"a" ascending:NO],
|
||||
]];
|
||||
|
||||
var start = (new Date).getTime();
|
||||
for (var i = 0; i < REPEATS; i++)
|
||||
{
|
||||
[ac setFilterPredicate:predicate];
|
||||
[ac addObject:[Sortable sortableWithA:i B:i * 2]];
|
||||
|
||||
var sorted = [ac arrangedObjects],
|
||||
last = ELEMENTS;
|
||||
|
||||
// Verify that all is well.
|
||||
for (var j = 0, count = [sorted count]; j < count; j++)
|
||||
{
|
||||
if (sorted[j].a >= last)
|
||||
[self fail:"array values should be descending (position: " + j + ")"];
|
||||
last = sorted[j];
|
||||
}
|
||||
}
|
||||
var end = (new Date).getTime();
|
||||
CPLog.warn("testAddObject_, sorted, clear filter on insert: " + (end - start) + "ms");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation Sortable : CPObject
|
||||
@@ -83,4 +122,12 @@
|
||||
int b @accessors;
|
||||
}
|
||||
|
||||
+ (id)sortableWithA:(int)anA B:(int)aB
|
||||
{
|
||||
var r = [Sortable new];
|
||||
r.a = anA;
|
||||
r.b = aB;
|
||||
return r;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user