views:

23

answers:

1

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. :D

+1  A: 

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]);
}
Vladimir
hello, thanks for your prompt reply. Another problem here is where to find the log information about the time duration? Through Console of Mac? or somewhere else? Thanks again for your help :D
J.Sun
if you run application in debug mode then log messages will be on debugger console (cmd+shift+R shortcut). otherwise I suppose you can find output in device logs through organizer window, but using logs while debugging is more common
Vladimir
Hey Vladimir, Thanks you so MUCH for your kind and detailed explanation. It really helps me a lot. Wish you a happy day :D
J.Sun
You're always welcome :)
Vladimir