iOS多個網(wǎng)絡(luò)請求完成后執(zhí)行下一步

在開發(fā)中,我們很容易遇到這樣的需求瓦宜,需要我們同時做多個網(wǎng)絡(luò)請求蔚万,所有網(wǎng)絡(luò)請求都完成后才能進行下一步的操作。如下載多個圖片临庇,下載完了才能展示反璃。

今天我們就來研究一下這個問題的解決方案。

1.首先假夺,我們創(chuàng)建一個項目淮蜈,然后做一般性的做法,不做任何處理去連續(xù)請求一個接口10次:

先在viewDidLoad中創(chuàng)建第一種情況.

//1.無處理
    UIButton *Btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    Btn1.frame = CGRectMake(100, 100, 100, 40);
    Btn1.backgroundColor = [UIColor grayColor];
    [Btn1 setTitle:@"noConduct" forState:UIControlStateNormal];
    [Btn1 addTarget:self action:@selector(Btn1) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:Btn1];

實現(xiàn)第一種情況的方法

//1.noConduct
-(void)Btn1{
    NSString *str = @"http://www.reibang.com/p/6930f335adba";
    NSURL *url = [NSURL URLWithString:str];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSURLSession *session = [NSURLSession sharedSession];
    
    for (int i=0; i<10; i++) {
        NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            
            NSLog(@"%d---%d",i,i);
            
        }];
        
        [task resume];
    }
    
    NSLog(@"end");
}

運行已卷,看看我們的控制臺輸出:

2017-12-04 17:10:10.503 DownImage[3289:261033] end
2017-12-04 17:10:10.676 DownImage[3289:261080] 0---0
2017-12-04 17:10:10.704 DownImage[3289:261080] 1---1
2017-12-04 17:10:10.754 DownImage[3289:261096] 4---4
2017-12-04 17:10:10.760 DownImage[3289:261080] 2---2
2017-12-04 17:10:10.800 DownImage[3289:261096] 5---5
2017-12-04 17:10:10.840 DownImage[3289:261080] 7---7
2017-12-04 17:10:10.844 DownImage[3289:261082] 6---6
2017-12-04 17:10:10.846 DownImage[3289:261096] 3---3
2017-12-04 17:10:10.888 DownImage[3289:261096] 8---8
2017-12-04 17:10:10.945 DownImage[3289:261080] 9---9

很明顯梧田,無任何處理情況下,end最先被打印出來,由于網(wǎng)絡(luò)請求的異步回調(diào)柿扣,然后各個網(wǎng)絡(luò)請求的回調(diào)順序是無序的肖方。

2.使用GCD的dispatch_group_t

viewDidLoad里:

//2.group
    UIButton *Btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    Btn2.frame = CGRectMake(100, 200, 100, 40);
    Btn2.backgroundColor = [UIColor grayColor];
    [Btn2 setTitle:@"group--" forState:UIControlStateNormal];
    [Btn2 addTarget:self action:@selector(Btn2) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:Btn2];

實現(xiàn):

//2.group--
-(void)Btn2{
    NSString *str = @"http://www.reibang.com/p/6930f335adba";
    NSURL *url = [NSURL URLWithString:str];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSURLSession *session = [NSURLSession sharedSession];
    
    dispatch_group_t downloadGroup = dispatch_group_create();
    for (int i=0; i<10; i++) {
        dispatch_group_enter(downloadGroup);
        
        NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            
            NSLog(@"%d---%d",i,i);
            dispatch_group_leave(downloadGroup);
            
        }];
        
        [task resume];
    }
    
    dispatch_group_notify(downloadGroup, dispatch_get_main_queue(), ^{
        NSLog(@"end");
    });
}

運行看看控制臺輸出:

2017-12-04 17:14:46.984 DownImage[3289:265374] 2---2
2017-12-04 17:14:46.987 DownImage[3289:265370] 1---1
2017-12-04 17:14:47.052 DownImage[3289:265383] 5---5
2017-12-04 17:14:47.065 DownImage[3289:265370] 4---4
2017-12-04 17:14:47.111 DownImage[3289:265379] 3---3
2017-12-04 17:14:47.121 DownImage[3289:265383] 6---6
2017-12-04 17:14:47.169 DownImage[3289:265383] 7---7
2017-12-04 17:14:47.192 DownImage[3289:265370] 9---9
2017-12-04 17:14:47.321 DownImage[3289:265383] 8---8
2017-12-04 17:14:47.747 DownImage[3289:265374] 0---0
2017-12-04 17:14:47.747 DownImage[3289:261033] end
2017-12-04 17:15:14.576 DownImage[3289:265942] 3---3
2017-12-04 17:15:14.626 DownImage[3289:265936] 2---2
2017-12-04 17:15:14.647 DownImage[3289:265944] 4---4
2017-12-04 17:15:14.648 DownImage[3289:265936] 0---0
2017-12-04 17:15:14.657 DownImage[3289:265943] 1---1
2017-12-04 17:15:14.709 DownImage[3289:265944] 5---5
2017-12-04 17:15:14.728 DownImage[3289:265944] 6---6
2017-12-04 17:15:14.734 DownImage[3289:265944] 7---7
2017-12-04 17:15:14.738 DownImage[3289:265943] 8---8
2017-12-04 17:15:14.816 DownImage[3289:265944] 9---9
2017-12-04 17:15:14.816 DownImage[3289:261033] end

從上兩次輸出可以看出闺魏,end確實是在所有網(wǎng)絡(luò)請求之后才輸出出來未状,這也是符合了我們的需求。

代碼中我們只添加了4行代碼

dispatch_group_t downloadGroup = dispatch_group_create();
dispatch_group_enter(downloadGroup);
dispatch_group_leave(downloadGroup);
dispatch_group_notify(downloadGroup, dispatch_get_main_queue(), ^{
    });

對以上4行代碼可理解為:創(chuàng)建一個dispatch_group_t析桥, 每次網(wǎng)絡(luò)請求前先dispatch_group_enter,請求回調(diào)后再dispatch_group_leave,對于enter和leave必須配合使用司草,有幾次enter就要有幾次leave,否則group會一直存在泡仗。當所有enter的block都leave后埋虹,會執(zhí)行dispatch_group_notify的block。

3.使用GCD的信號量dispatch_semaphore_t
//3.semaphore
    UIButton *Btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
    Btn3.frame = CGRectMake(100, 300, 100, 40);
    Btn3.backgroundColor = [UIColor grayColor];
    [Btn3 setTitle:@"semaphore" forState:UIControlStateNormal];
    [Btn3 addTarget:self action:@selector(Btn3) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:Btn3];
//3.semaphore--
-(void)Btn3{
    NSString *str = @"http://www.reibang.com/p/6930f335adba";
    NSURL *url = [NSURL URLWithString:str];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSURLSession *session = [NSURLSession sharedSession];
    
    dispatch_semaphore_t sem = dispatch_semaphore_create(0);
    for (int i=0; i<10; i++) {
        
        NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            
            NSLog(@"%d---%d",i,i);
            count++;
            if (count==10) {
                dispatch_semaphore_signal(sem);
                count = 0;
            }
            
        }];
        
        [task resume];
    }
    dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
    
    dispatch_async(dispatch_get_main_queue(), ^{
        NSLog(@"end");
    });
}

運行看看控制臺輸出:

2017-12-04 17:36:49.098 DownImage[3428:283651] 2---2
2017-12-04 17:36:49.144 DownImage[3428:284210] 0---0
2017-12-04 17:36:49.152 DownImage[3428:284213] 3---3
2017-12-04 17:36:49.158 DownImage[3428:283651] 1---1
2017-12-04 17:36:49.167 DownImage[3428:284210] 4---4
2017-12-04 17:36:49.235 DownImage[3428:284213] 8---8
2017-12-04 17:36:49.249 DownImage[3428:283651] 5---5
2017-12-04 17:36:49.252 DownImage[3428:283651] 7---7
2017-12-04 17:36:49.324 DownImage[3428:283651] 9---9
2017-12-04 17:36:49.468 DownImage[3428:284214] 6---6
2017-12-04 17:36:49.469 DownImage[3428:283554] end
2017-12-04 17:37:11.554 DownImage[3428:284747] 0---0
2017-12-04 17:37:11.555 DownImage[3428:284733] 1---1
2017-12-04 17:37:11.627 DownImage[3428:284748] 5---5
2017-12-04 17:37:11.661 DownImage[3428:284748] 2---2
2017-12-04 17:37:11.688 DownImage[3428:284747] 4---4
2017-12-04 17:37:11.709 DownImage[3428:284747] 6---6
2017-12-04 17:37:11.770 DownImage[3428:284733] 7---7
2017-12-04 17:37:11.774 DownImage[3428:284733] 8---8
2017-12-04 17:37:11.824 DownImage[3428:284747] 9---9
2017-12-04 17:37:11.899 DownImage[3428:284733] 3---3
2017-12-04 17:37:11.900 DownImage[3428:283554] end

從輸出可以看出娩怎,這樣的方法也是滿足我們的需求的搔课,在這個方法中,我們使用了

dispatch_semaphore_t sem = dispatch_semaphore_create(0);
dispatch_semaphore_signal(sem);
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);

對這三句代碼可以這樣理解:dispatch_semaphore信號量為基于計數(shù)器的一種多線程同步機制截亦。如果semaphore計數(shù)大于等于1爬泥,計數(shù)-1,返回崩瓤,程序繼續(xù)運行袍啡。如果計數(shù)為0,則等待却桶。dispatch_semaphore_signal(semaphore)為計數(shù)+1操作,dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER)為設(shè)置等待時間境输,這里設(shè)置的等待時間是一直等待。

對于以上代碼通俗一點就是颖系,開始為0嗅剖,等待,等10個網(wǎng)絡(luò)請求都完成了嘁扼,dispatch_semaphore_signal(semaphore)為計數(shù)+1信粮,然后計數(shù)-1返回,程序繼續(xù)執(zhí)行偷拔。 (這里也就是為什么有個count變量的原因蒋院,記錄網(wǎng)絡(luò)回調(diào)的次數(shù),回調(diào)10次之后再發(fā)信號量莲绰,使后面程序繼續(xù)運行)欺旧。

4.考慮新需求,10個網(wǎng)絡(luò)請求順序回調(diào)蛤签。

需求需要順序回調(diào)辞友,即執(zhí)行完第一個網(wǎng)絡(luò)請求后,第二個網(wǎng)絡(luò)請求回調(diào)才可被執(zhí)行,簡單來講就是輸出得是0,1,2,3...9這種方式的称龙。

對于這個需求我也是根據(jù)自己最近做的項目來提的留拾,因為網(wǎng)絡(luò)請求回調(diào)的異步性,我們雖可以控制網(wǎng)絡(luò)請求的順序執(zhí)行鲫尊,卻不能控制它的完成回調(diào)順序痴柔。這就有點傷了,目前我項目是找到了解決方案疫向,但這個問題還沒有找到解決辦法咳蔚,提出來跟大家討論一下。(請忽略網(wǎng)絡(luò)請求執(zhí)行搔驼,回調(diào)谈火,在回調(diào)里請求下一個接口的辦法,討論還有沒有別的方法,最好show the code).

最后舌涨,貼點NSOperation的代碼糯耍,為了解決新需求所寫,由于網(wǎng)絡(luò)請求回調(diào)異步性不能滿足需求囊嘉,但若不是網(wǎng)絡(luò)請求等異步回調(diào)的方式温技,這樣的做法是可以的,大家可以試試.

//4.NSOperation
    UIButton *Btn4 = [UIButton buttonWithType:UIButtonTypeCustom];
    Btn4.frame = CGRectMake(100, 400, 100, 40);
    Btn4.backgroundColor = [UIColor grayColor];
    [Btn4 setTitle:@"NSOperation" forState:UIControlStateNormal];
    [Btn4 addTarget:self action:@selector(Btn4) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:Btn4];
//4.NSOperation
-(void)Btn4{
    NSString *str = @"http://www.reibang.com/p/6930f335adba";
    NSURL *url = [NSURL URLWithString:str];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSURLSession *session = [NSURLSession sharedSession];
    
    NSMutableArray *operationArr = [[NSMutableArray alloc]init];
    for (int i=0; i<10; i++) {
        NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
            NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                
                NSLog(@"%d---%d",i,i);
                
            }];
            
            [task resume];

            //非網(wǎng)絡(luò)請求
            NSLog(@"noRequest-%d",i);
        }];
        
        [operationArr addObject:operation];
        if (i>0) {
            NSBlockOperation *operation1 = operationArr[i-1];
            NSBlockOperation *operation2 = operationArr[i];
            [operation2 addDependency:operation1];
        }
    }
    
    NSOperationQueue *queue = [[NSOperationQueue alloc]init];
    [queue addOperations:operationArr waitUntilFinished:NO];  //YES會阻塞當前線程
#warning - 絕對不要在應(yīng)用主線程中等待一個Operation,只能在第二或次要線程中等待哗伯。阻塞主線程將導(dǎo)致應(yīng)用無法響應(yīng)用戶事件,應(yīng)用也將表現(xiàn)為無響應(yīng)荒揣。
    
}

運行結(jié)果:

2017-12-04 18:03:10.224 DownImage[3584:304363] noRequest-0
2017-12-04 18:03:10.226 DownImage[3584:304362] noRequest-1
2017-12-04 18:03:10.226 DownImage[3584:304363] noRequest-2
2017-12-04 18:03:10.231 DownImage[3584:304363] noRequest-3
2017-12-04 18:03:10.232 DownImage[3584:304362] noRequest-4
2017-12-04 18:03:10.233 DownImage[3584:304362] noRequest-5
2017-12-04 18:03:10.233 DownImage[3584:304363] noRequest-6
2017-12-04 18:03:10.234 DownImage[3584:304363] noRequest-7
2017-12-04 18:03:10.235 DownImage[3584:304363] noRequest-8
2017-12-04 18:03:10.236 DownImage[3584:304363] noRequest-9
2017-12-04 18:03:10.408 DownImage[3584:304597] 2---2
2017-12-04 18:03:10.408 DownImage[3584:304597] 0---0
2017-12-04 18:03:10.409 DownImage[3584:304597] 1---1
2017-12-04 18:03:10.461 DownImage[3584:304597] 5---5
2017-12-04 18:03:10.476 DownImage[3584:304363] 4---4
2017-12-04 18:03:10.477 DownImage[3584:304365] 6---6
2017-12-04 18:03:10.518 DownImage[3584:304365] 7---7
2017-12-04 18:03:10.537 DownImage[3584:304596] 8---8
2017-12-04 18:03:10.547 DownImage[3584:304362] 9---9
2017-12-04 18:03:11.837 DownImage[3584:304362] 3---3
2017-12-04 18:04:27.699 DownImage[3584:306401] noRequest-0
2017-12-04 18:04:27.700 DownImage[3584:306405] noRequest-1
2017-12-04 18:04:27.701 DownImage[3584:306401] noRequest-2
2017-12-04 18:04:27.701 DownImage[3584:306405] noRequest-3
2017-12-04 18:04:27.702 DownImage[3584:306401] noRequest-4
2017-12-04 18:04:27.702 DownImage[3584:306405] noRequest-5
2017-12-04 18:04:27.703 DownImage[3584:306401] noRequest-6
2017-12-04 18:04:27.703 DownImage[3584:306401] noRequest-7
2017-12-04 18:04:27.704 DownImage[3584:306401] noRequest-8
2017-12-04 18:04:27.704 DownImage[3584:306401] noRequest-9
2017-12-04 18:04:27.772 DownImage[3584:306397] 2---2
2017-12-04 18:04:27.779 DownImage[3584:306401] 0---0
2017-12-04 18:04:27.782 DownImage[3584:306409] 1---1
2017-12-04 18:04:27.800 DownImage[3584:306405] 3---3
2017-12-04 18:04:27.851 DownImage[3584:306401] 6---6
2017-12-04 18:04:27.855 DownImage[3584:306397] 5---5
2017-12-04 18:04:27.915 DownImage[3584:306397] 7---7
2017-12-04 18:04:27.951 DownImage[3584:306397] 9---9
2017-12-04 18:04:27.953 DownImage[3584:306405] 8---8
2017-12-04 18:04:28.476 DownImage[3584:306409] 4---4
5.還是使用信號量semaphore完成4的需求
//5.semaphore---order
    UIButton *Btn5 = [UIButton buttonWithType:UIButtonTypeCustom];
    Btn5.frame = CGRectMake(100, 500, 100, 40);
    Btn5.backgroundColor = [UIColor grayColor];
    [Btn5 setTitle:@"order" forState:UIControlStateNormal];
    [Btn5 addTarget:self action:@selector(Btn5) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:Btn5];
//5.semaphore--order
-(void)Btn5{
    NSString *str = @"http://www.reibang.com/p/6930f335adba";
    NSURL *url = [NSURL URLWithString:str];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSURLSession *session = [NSURLSession sharedSession];
    
    dispatch_semaphore_t sem = dispatch_semaphore_create(0);
    for (int i=0; i<10; i++) {
        
        NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            
            NSLog(@"%d---%d",i,i);
            dispatch_semaphore_signal(sem);
        }];
        
        [task resume];
        dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
    }
    
    dispatch_async(dispatch_get_main_queue(), ^{
        NSLog(@"end");
    });
}

我們看看運行結(jié)果:

2017-12-05 10:17:28.175 DownImage[938:51296] 0---0
2017-12-05 10:17:28.331 DownImage[938:51289] 1---1
2017-12-05 10:17:28.506 DownImage[938:51289] 2---2
2017-12-05 10:17:28.563 DownImage[938:51289] 3---3
2017-12-05 10:17:28.662 DownImage[938:51289] 4---4
2017-12-05 10:17:28.733 DownImage[938:51296] 5---5
2017-12-05 10:17:28.792 DownImage[938:51296] 6---6
2017-12-05 10:17:28.856 DownImage[938:51286] 7---7
2017-12-05 10:17:29.574 DownImage[938:51289] 8---8
2017-12-05 10:17:29.652 DownImage[938:51286] 9---9
2017-12-05 10:17:29.653 DownImage[938:45252] end
2017-12-05 10:17:46.341 DownImage[938:51608] 0---0
2017-12-05 10:17:47.967 DownImage[938:51607] 1---1
2017-12-05 10:17:48.038 DownImage[938:51603] 2---2
2017-12-05 10:17:48.132 DownImage[938:51603] 3---3
2017-12-05 10:17:48.421 DownImage[938:51608] 4---4
2017-12-05 10:17:48.537 DownImage[938:51289] 5---5
2017-12-05 10:17:48.646 DownImage[938:51289] 6---6
2017-12-05 10:17:48.939 DownImage[938:51289] 7---7
2017-12-05 10:17:50.537 DownImage[938:51607] 8---8
2017-12-05 10:17:50.615 DownImage[938:51289] 9---9
2017-12-05 10:17:50.616 DownImage[938:45252] end

我們對比 3 的代碼,3 中我們只在最后也就是循環(huán)結(jié)束后調(diào)用dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER)焊刹,循環(huán)中當網(wǎng)絡(luò)請求回調(diào)10次(也就是都回調(diào)完)后系任,使傳入的信號量加1:( dispatch_semaphore_signal(sem) ),這時等待結(jié)束,然后進行后續(xù)的操作虐块。

在這個方法里俩滥,我們每一次遍歷,都讓其dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER)贺奠,這個時候線程會等待霜旧,阻塞當前線程,直到dispatch_semaphore_signal(sem)調(diào)用之后儡率,而我們dispatch_semaphore_signal(sem)是在網(wǎng)絡(luò)請求的回調(diào)里調(diào)用的挂据,所以這個方法的邏輯是:

遍歷—>發(fā)起任務(wù)—>等待—>任務(wù)完成信號量加1—>等待結(jié)束,開始下一個任務(wù)
發(fā)起任務(wù)—>等待—>任務(wù)完成信號量加1—>等待結(jié)束,開始下一個任務(wù)
發(fā)起任務(wù)—>等待—>任務(wù)完成信號量加1—>等待結(jié)束,開始下一個任務(wù)

這樣循環(huán)的模式,一個任務(wù)完成才能接著去做下面的任務(wù),滿足我們的需求儿普。

但我們也要發(fā)現(xiàn)這樣一個問題崎逃,我們使用這種方式,可以明顯感覺出整個過程需要花費的時間大大增加了眉孩,不像我們 3 中同時(幾乎)開啟任務(wù)等待完成回調(diào)个绍,這里是一個網(wǎng)絡(luò)請求發(fā)出勒葱,等待,完成后發(fā)出第二個網(wǎng)絡(luò)請求巴柿,等待凛虽,完成后再發(fā)出第三個,這樣我們等待的時間是10個網(wǎng)絡(luò)請求每一個回調(diào)時間的和广恢,在時間上大大增加了消耗凯旋,而且對于dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER),它是會阻塞線程的袁波,我們?nèi)绻枰诰W(wǎng)絡(luò)請求完成后修改UI瓦阐,那這種方式會影響我們的界面交互,接下來我們對比一下兩者時間消耗:

3-------------3----------3-------
2017-12-05 10:29:51.178 DownImage[938:56971] 2---2
2017-12-05 10:29:51.193 DownImage[938:57200] 0---0
2017-12-05 10:29:51.202 DownImage[938:56631] 3---3
2017-12-05 10:29:51.248 DownImage[938:56971] 1---1
2017-12-05 10:29:51.262 DownImage[938:56971] 5---5
2017-12-05 10:29:51.291 DownImage[938:56631] 6---6
2017-12-05 10:29:51.375 DownImage[938:56631] 7---7
2017-12-05 10:29:51.384 DownImage[938:56631] 4---4
2017-12-05 10:29:51.434 DownImage[938:56971] 8---8
2017-12-05 10:29:51.487 DownImage[938:57199] 9---9
2017-12-05 10:29:51.488 DownImage[938:45252] end

5-------------5----------5-------
2017-12-05 10:29:52.190 DownImage[938:56631] 0---0
2017-12-05 10:29:52.304 DownImage[938:57199] 1---1
2017-12-05 10:29:52.432 DownImage[938:56971] 2---2
2017-12-05 10:29:52.520 DownImage[938:56971] 3---3
2017-12-05 10:29:52.576 DownImage[938:56631] 4---4
2017-12-05 10:29:52.628 DownImage[938:56971] 5---5
2017-12-05 10:29:52.706 DownImage[938:56631] 6---6
2017-12-05 10:29:52.764 DownImage[938:56971] 7---7
2017-12-05 10:29:52.853 DownImage[938:56631] 8---8
2017-12-05 10:29:52.925 DownImage[938:56971] 9---9
2017-12-05 10:29:52.926 DownImage[938:45252] end

看得出3花費時間為51.488 - 51.178約300多ms
--- ---5花費時間為52.926 - 52.190約700多ms

所以大家還請謹慎使用。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末篷牌,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子踏幻,更是在濱河造成了極大的恐慌枷颊,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,968評論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件该面,死亡現(xiàn)場離奇詭異夭苗,居然都是意外死亡,警方通過查閱死者的電腦和手機隔缀,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,601評論 2 382
  • 文/潘曉璐 我一進店門题造,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人猾瘸,你說我怎么就攤上這事界赔。” “怎么了牵触?”我有些...
    開封第一講書人閱讀 153,220評論 0 344
  • 文/不壞的土叔 我叫張陵淮悼,是天一觀的道長。 經(jīng)常有香客問我揽思,道長袜腥,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,416評論 1 279
  • 正文 為了忘掉前任钉汗,我火速辦了婚禮羹令,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘损痰。我一直安慰自己福侈,他們只是感情好,可當我...
    茶點故事閱讀 64,425評論 5 374
  • 文/花漫 我一把揭開白布徐钠。 她就那樣靜靜地躺著癌刽,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上显拜,一...
    開封第一講書人閱讀 49,144評論 1 285
  • 那天衡奥,我揣著相機與錄音,去河邊找鬼远荠。 笑死矮固,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的譬淳。 我是一名探鬼主播档址,決...
    沈念sama閱讀 38,432評論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼邻梆!你這毒婦竟也來了守伸?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,088評論 0 261
  • 序言:老撾萬榮一對情侶失蹤浦妄,失蹤者是張志新(化名)和其女友劉穎尼摹,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體剂娄,經(jīng)...
    沈念sama閱讀 43,586評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡蠢涝,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,028評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了阅懦。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片和二。...
    茶點故事閱讀 38,137評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖耳胎,靈堂內(nèi)的尸體忽然破棺而出惯吕,到底是詐尸還是另有隱情,我是刑警寧澤场晶,帶...
    沈念sama閱讀 33,783評論 4 324
  • 正文 年R本政府宣布混埠,位于F島的核電站,受9級特大地震影響诗轻,放射性物質(zhì)發(fā)生泄漏钳宪。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,343評論 3 307
  • 文/蒙蒙 一扳炬、第九天 我趴在偏房一處隱蔽的房頂上張望吏颖。 院中可真熱鬧,春花似錦恨樟、人聲如沸半醉。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,333評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽缩多。三九已至呆奕,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間衬吆,已是汗流浹背梁钾。 一陣腳步聲響...
    開封第一講書人閱讀 31,559評論 1 262
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留逊抡,地道東北人姆泻。 一個月前我還...
    沈念sama閱讀 45,595評論 2 355
  • 正文 我出身青樓,卻偏偏與公主長得像冒嫡,于是被迫代替她去往敵國和親拇勃。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 42,901評論 2 345

推薦閱讀更多精彩內(nèi)容