GCD latency execution and gcd latency
1. Comparison of GCD and NSThread latency
Import the encapsulated GCD
# Import "GCD. h"
-(Void) threadEvent :( id) sender {
NSLog (@ "NSThread thread event ");
}
-(Void) viewDidLoad {
[Super viewDidLoad];
// [Self initConcurrent];
NSLog (@ "start ");
// The NSThread method delays the execution of operations
[Self defined mselector: @ selector (threadEvent :)
WithObject: self
Afterdelay: 2.0];
// Cancel the currently registered delayed operation
// [NSObject cancelPreviousPerformRequestsWithTarget: self];
// Perform operations with CCD Delay
[GCDQueue executeInMainQueue: ^ {
NSLog (@ "2 seconds delayed execution ");
} AfterDelaySecs: 2.f];
}
Execution result:
11:24:02. 654 GCDDelay [2735: 213842]Start
11:24:04. 655 GCDDelay [2735: 213842] NSThreadThread event
11:24:04. 796 GCDDelay [2735: 213842]Latency2Seconds
We can see that the NSthread time is accurate.
2. Open [NSObject cancelPreviousPerformRequestsWithTarget: self];
Execution result:
11:30:56. 768 GCDDelay [2796: 220332]Start
11:30:58. 769 GCDDelay [2796: 220332]Latency2Seconds
It can be seen that the NSThread thread is canceled and not executed.
Iii. Advantages and Disadvantages of GCD delayed execution: the code format is more integrated, concise, and easy to write. Disadvantages:
LatencyThe operation cannot be canceled because the precision is not high.
Iv. Differences between NSThread and GCD NSThread latency
High Accuracy,Can cancel the current delayed operation
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.