粗略的计算一段代码的执行时间.
本文也是从别的地方看来的,先贴地址,不保证是原文,只能是我看到的文章出处:http://blog.csdn.net/yexiaozi_007/article/details/7966934
//方法一: 使用系统时间
NSDate* tmpStartData = [NSDate date];
//You code here...
double deltaTime = [[NSDate date] timeIntervalSinceDate:tmpStartData];
NSLog(@">>>>>>>>>>cost time = %f ms", deltaTime*1000);
复制代码
//方法二:
#import <mach/mach_time.h>
uint64_t start = mach_absolute_time();
//You code here...
uint64_t end = mach_absolute_time();
uint64_t elapsed = end - start;
mach_timebase_info_data_t info;
if (mach_timebase_info (&info) != KERN_SUCCESS)
{
printf ("mach_timebase_info failed\n");
}
uint64_t nanosecs = elapsed * info.numer / info.denom;
uint64_t millisecs = nanosecs / 1000000;
NSLog(@">>>>>>>>>>cost time = %ld ms", millisecs);
复制代码