假如有3个任务如下

- (int)mission1
{
    [NSThread sleepForTimeInterval:1];  //模拟耗时操作
    return 1;
}

- (int)mission2
{
    [NSThread sleepForTimeInterval:2];  //模拟耗时操作
    return 2;
}

- (int)mission3
{
    [NSThread sleepForTimeInterval:3];  //模拟耗时操作
    return 3;
}

1.普通的执行方法,消耗时间为6秒

NSDate* startTime = [NSDate date];

int ans1 = [self mission1];
int ans2 = [self mission2];
int ans3 = [self mission3];

self.textView.text = [NSString stringWithFormat:@"%i %i %i", ans1, ans2, ans3];

NSDate* endTime = [NSDate date];
NSLog(@"%f", [endTime timeIntervalSinceDate:startTime]);
View Code

相关文章: