Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * _arraySize - UITextField with desired arraySize
- * _position - UITextField with desired position of wanted element
- * _testSize - UITextField with number of iterations
- */
- -(IBAction)stertTest:(id)sender
- {
- /*
- * Prepare array for testing
- */
- NSMutableArray *testArray = [NSMutableArray array];
- int elementCount = [_arraySize.text intValue];;
- int testedElementPosition = [_position.text intValue];;
- for(int i=0; i< elementCount; i++)
- {
- TestObject *t = [[TestObject alloc] init];
- if(i == testedElementPosition)
- {
- t.name = @"bar";
- } else {
- t.name = [NSString stringWithFormat:@"%@%i",@"foo",arc4random()];
- }
- [testArray addObject:t];
- }
- int testSize = [_size.text intValue];
- /*
- * Testing predicate
- */
- NSDate *start = [NSDate date];
- for(int i=0; i<testSize; i++)
- {
- [testArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"name = %@",@"bar"]];
- }
- NSDate *methodFinish = [NSDate date];
- NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:start];
- _predicate.text = [NSString stringWithFormat:@"%f",executionTime];
- /*
- * Testing loop
- */
- start = [NSDate date];
- for(int i=0; i<testSize; i++)
- {
- [self findObject:@"bar" inArray:testArray];
- }
- methodFinish = [NSDate date];
- executionTime = [methodFinish timeIntervalSinceDate:start];
- _loop.text = [NSString stringWithFormat:@"%f",executionTime];
- }
- -(TestObject*)findObject:(NSString*)search inArray:(NSArray*)array{
- for (TestObject* obj in array){
- if([obj.name isEqualToString: search])
- return obj;
- }
- return nil;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement