Reputation: 5451
Please refer to the code below:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
//... some other code
if (imageLoadingQueue == nil) {
imageLoadingQueue = [[NSOperationQueue alloc] init];
[imageLoadingQueue setName:@"Image Loading Queue"];
}
//... some other code
return cell;
}
Now as we know the method - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
is called every time we scroll but refer to the conditions: if (cell == nil)
& if (imageLoadingQueue == nil)
. This condition is checked again & again always.
So I wanted to know how much performance overhead this if condition costs ?
EDIT: How do we measure that ? Any tool ?
Upvotes: 0
Views: 212
Reputation: 881303
The if
statement itself will be negligible. It's possible that the condition used within the if
statement may be significant (as in if (somethingThatTakesTenSeconds()) ...
) but not so in this case, simply checking pointers against the nil
value.
In any case, it hardly matters. If you need to select whether or not something happens, you have to use a selection statement, be it if
, select
, or a ternary operation. So how onerous it is doesn't really enter into the equation.
Upvotes: 4