if let _ = value or if value != nil? Comparing performance of not nil syntax variations.
Run the command below and compare the results.
$ swift testModify
attemptsproperty inNotNilChallengeTestsclass to check performance for more / fewer runs.
- Device: MacBook Pro (15-inch, Mid 2015, 2.2GHz Intel Core i7, 16GB RAM)
- OS: macOS High Sierra 10.13.3
- Swift: 4.1.2
- Attempts: 10,000,000
| Variant | Average duration |
|---|---|
if let _ = value |
0.165 sec |
if value != nil |
0.184 sec |
if let _ = value is about 12% faster than if value != nil.