Skip to content
Comparing performance of not nil syntax variations
Swift
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Tests
.gitignore
.travis.yml
LICENSE
Package.swift
README.md

README.md

Not Nil Challenge

Swift 4.2.1 Build Status

if let _ = value or if value != nil? Comparing performance of not nil syntax variations.

Usage

Run the command below and compare the results.

$ swift test

Modify attempts property in NotNilChallengeTests class to check performance for more / fewer runs.

Test Environment

  • 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

Test Results

Variant Average duration
if let _ = value 0.165 sec
if value != nil 0.184 sec

Conclusions

if let _ = value is about 12% faster than if value != nil.

You can’t perform that action at this time.