Hey there, I am fresh to iPhone development and Objective C. Sorry if this question is too stupid….
Here is my problem, I want to calculate the time taken by one of my function. like UIGetScreenImage. Here is the code:
-(void)screenCapture{
CGImageRef screen = UIGetScreenImage();
UIImage* image = [UIImage imageWithCGImage:screen];
CGImageRelease(screen);
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
what should I do to calculate the time taken by this process? Sample code would be appreciated.
Thanks for your kind assistance. Look forward to your replies and ideas. 😀
You can get current date on method start and finish and check time passed between those 2 moments:
-(void)screenCapture{NSDate* startDate = [NSDate date];
…
NSDate* finishDate = [NSDate date];
NSLog(@”%f”, [finishDate timeIntervalSinceDate: startDate]);
}
Edit: I believe my approach described above is (to put it mildly) not the best solution to measure process time. Now I use approach described in “Big Nerd Ranch” blog here that uses
mach_absolute_timefunction. I copied the code from the post to illustrate that method – with this code snippet you can measure rub time of arbitrary block: