简体   繁体   中英

Measuring smooth scrolling performance

Is there any way to measure scroll performance in an iPhone app, eg updates per second? I'm trying various techniques to improve the scrolling performance but it's sometimes 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.

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