计算fps帧率 iOS

[[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);
    }
}

原理:

由于iOS设备每加载一帧都会调用 displayLinkAction 函数

设置全局变量,求1s内加载了多少帧,然后除以第一帧和最后一帧的时间间隔。

在北京的灯中,有一盏是我家的。这个梦何时可以实现?哪怕微微亮。北京就像魔鬼训练营,有能力的留,没能力的走……
原文地址:https://www.cnblogs.com/huangzs/p/14467457.html