开发者

Measuring smooth scrolling performance

Is there any way to measure scroll performance in an iPhone app, e.g. updates per second? I'm trying various techniques to improve the scrolling performance but it's som开发者_如何学编程etimes hard to judge if they're actually having an effect.


if you have a scroll delegate, you can implement the method scrollViewDidScroll:. Specifically:

//header:
@interface MyClass : NSObject <UIScrollViewDelegate> {
    CFAbsoluteTime last;
    int updateCount;
    CFTimeInterval timeTotal;
}
@end

//implementation:
@implementation MyClass

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CFAbsoluteTime time = CFAbsoluteTimeGetCurrent();
    if (last > 0) {
        timeTotal += time - last;
        ++updateCount;
        if (timeTotal > 1) {
            NSLog(@"Updates Per Second: %.2f", updateCount / timeTotal);
            updateCount = 0;
            timeTotal = 0;
        }
    }
    last = time;
}

@end

Something like that. It's untested, so the logging may be incorrect. But to use it, just assign your delegate to the scrollview.delegate property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜