简体   繁体   中英

Measuring the UITableView Scrolling Performance - iphone

I am trying to measure the scrolling performance for my UITableView, between using subview and drawing the view myself. As we may know about scrolling performance, there are a couple of famous articles ( Tweetie , TableViewSuite , Glassy and Glassy2 that help us with the technique and all will point to the same point: when we have lots of subviews, we should go with drawRect.

The problem is that I do not know how to benchmark the performance in either case: using subview or drawing. And drawing is actually harder to do than subview, so it is hard to convince everybody to go with drawing directly. I am trying to write 2 small samples and using 2 techniques and benchmark the performance result. I am currently trying with this, but it generates the same results for both techniques:

NSDate *date = [NSDate date];
    static NSString *CellIdentifier = @"CellIdentifier";

    CustomDrawingTableViewCell *cell = (CustomDrawingTableViewCell *) [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
         cell = [[[CustomDrawingTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                                                             reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...
    // Main Code is HERE


    NSDate *date2 = [NSDate date];
    NSLog(@"%f", [date2 timeIntervalSinceDate:date]);
    return cell;

My Cell has around 4 images, 1 text

I'd suggest using Instruments rather than trying to run the test directly in your code. The Core Animation tool will track the actual number of frames per second (FPS) that your app's displaying.

Firstly, I will confirm that if you have a lot of subviews, you WILL get huge performance benefits using drawRect and the Tweetie method (for example). We have a project where each cell has something like 14 sub-views and it ran like treacle on older devices. Having moved to doing it directly, it runs at iphone4 speeds even on old 3G (not 3GS) devices.

So it IS worth it.

Measuring wise though, you're measuring at the wrong point. You are measuring the time to either dequeue a cell or init a new one, neither of which have anything to do with the time it takes to render on screen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM