// // FPS.m // Awars III // // Created by 桐谷 諭史 on 2016/02/01. // Copyright © 2016年 Killery. All rights reserved. // #import "FPS.h" @implementation FPS -(id)init{ timer = [NSTimer scheduledTimerWithTimeInterval:1.0/30 target:self selector:@selector(FPSFnc:) userInfo:nil repeats:YES]; return self; } -(void)FPSFnc:(id)sender{ GetFrameRate(); } int GetFrameRateMAX(){ static CFTimeInterval lastTime = 0; static int fps = 0; static bool fpsInit = false; if(!fpsInit){ lastTime = CFAbsoluteTimeGetCurrent(); fpsInit = true; } CFTimeInterval currentTime = CFAbsoluteTimeGetCurrent(); fps++; if(currentTime - lastTime >= 1){ NSLog(@"MAXFPS = %d", fps); fps = 0; lastTime = currentTime; } return fps; } int GetFrameRate(){ static CFTimeInterval lastTime = 0; static int fps = 0; static bool fpsInit = false; if(!fpsInit){ lastTime = CFAbsoluteTimeGetCurrent(); fpsInit = true; } CFTimeInterval currentTime = CFAbsoluteTimeGetCurrent(); fps++; if(currentTime - lastTime >= 1){ NSLog(@"FPS = %d", fps); fps = 0; lastTime = currentTime; } return fps; } @end