Last active
February 28, 2020 08:40
-
-
Save 1024jp/16c177d4c2d037b4e088bf844f87b938 to your computer and use it in GitHub Desktop.
Swift String cast timing comparison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Foo { | |
var string: String | |
} | |
protocol Bar { | |
var string: NSString | |
} | |
class FooManager: Manager, Foo { | |
var string: String { self.attributedString().string } | |
} | |
class BarManager: Manager, Bar { | |
var string: NSString { self.attributedString().string as NSString } | |
} | |
// 同じNSStringが欲しいときに ↓の2つで所要時間が違う。下の方がちょっと速い。 | |
let string1 = fooManager.string as NSString | |
let string2 = barManager.string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment