Advertisement
Guest User

Untitled

a guest
Nov 16th, 2013
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * _arraySize - UITextField with desired arraySize
  3. * _position - UITextField with desired position of wanted element
  4. * _testSize - UITextField with number of iterations
  5. */
  6.  
  7. -(IBAction)stertTest:(id)sender
  8. {
  9.    
  10.     /*
  11.      *  Prepare array for testing
  12.      */
  13.    
  14.     NSMutableArray *testArray = [NSMutableArray array];
  15.    
  16.     int elementCount = [_arraySize.text intValue];;
  17.     int testedElementPosition = [_position.text intValue];;
  18.    
  19.    
  20.     for(int i=0; i< elementCount; i++)
  21.     {
  22.         TestObject *t = [[TestObject alloc] init];
  23.         if(i == testedElementPosition)
  24.         {
  25.             t.name = @"bar";
  26.         } else {
  27.             t.name = [NSString stringWithFormat:@"%@%i",@"foo",arc4random()];
  28.         }
  29.         [testArray addObject:t];
  30.     }
  31.    
  32.    
  33.     int testSize = [_size.text intValue];
  34.    
  35.    
  36.     /*
  37.      *  Testing predicate
  38.      */
  39.    
  40.     NSDate *start = [NSDate date];
  41.    
  42.     for(int i=0; i<testSize; i++)
  43.     {
  44.         [testArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"name = %@",@"bar"]];
  45.     }
  46.    
  47.     NSDate *methodFinish = [NSDate date];
  48.     NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:start];
  49.    
  50.     _predicate.text = [NSString stringWithFormat:@"%f",executionTime];
  51.    
  52.    
  53.     /*
  54.      *  Testing loop
  55.      */
  56.    
  57.     start = [NSDate date];
  58.    
  59.     for(int i=0; i<testSize; i++)
  60.     {
  61.         [self findObject:@"bar" inArray:testArray];
  62.     }
  63.    
  64.     methodFinish = [NSDate date];
  65.     executionTime = [methodFinish timeIntervalSinceDate:start];
  66.    
  67.     _loop.text = [NSString stringWithFormat:@"%f",executionTime];
  68.    
  69.    
  70. }
  71.  
  72. -(TestObject*)findObject:(NSString*)search inArray:(NSArray*)array{
  73.     for (TestObject* obj in array){
  74.         if([obj.name isEqualToString: search])
  75.             return obj;
  76.     }
  77.     return nil;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement