美文网首页
iOS 计算fps

iOS 计算fps

作者: CocoaJason | 来源:发表于2019-12-29 21:01 被阅读0次
    [[CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkAction:)] addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
    
    - (void)displayLinkAction:(CADisplayLink *)link {
        static NSTimeInterval lastTime = 0;
        static NSInteger frameCount = 0;
        if (lastTime == 0) {
            lastTime = link.timestamp;
            return;
        }
        frameCount ++;
        NSTimeInterval paseTime = link.timestamp - lastTime;
        if (paseTime > 1) {
            NSInteger fps = frameCount / paseTime;
            lastTime = link.timestamp;
            frameCount = 0;
            NSLog(@"%ld",fps);
        }
    }
    
    2019-12-29 20:45:16.035014+0800 CADisplayLink[14509:274268] 52
    2019-12-29 20:45:17.034081+0800 CADisplayLink[14509:274268] 59
    2019-12-29 20:45:18.034943+0800 CADisplayLink[14509:274268] 59
    2019-12-29 20:45:19.034156+0800 CADisplayLink[14509:274268] 59
    2019-12-29 20:45:20.034959+0800 CADisplayLink[14509:274268] 59
    2019-12-29 20:45:21.034505+0800 CADisplayLink[14509:274268] 59
    2019-12-29 20:45:22.034900+0800 CADisplayLink[14509:274268] 59
    2019-12-29 20:45:23.034121+0800 CADisplayLink[14509:274268] 59
    2019-12-29 20:45:24.034044+0800 CADisplayLink[14509:274268] 59
    2019-12-29 20:45:25.034870+0800 CADisplayLink[14509:274268] 59
    2019-12-29 20:45:26.033931+0800 CADisplayLink[14509:274268] 59
    2019-12-29 20:45:27.034908+0800 CADisplayLink[14509:274268] 59
    2019-12-29 20:45:28.034852+0800 CADisplayLink[14509:274268] 59
    

    相关文章

      网友评论

          本文标题:iOS 计算fps

          本文链接:https://www.haomeiwen.com/subject/dhjuoctx.html