开发者

Measuring smooth scrolling performance

开发者 https://www.devze.com 2023-01-02 11:47 出处:网络
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

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

精彩评论

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