[英]Swift performance and CustomStringConvertible protocol
在這里,我嘗試對我的distinct函數進行基准測試,該函數通過刪除phoneNumber屬性中的重復項來接收隨機對象的數組並返回獨特的數組:當我為Person類實現CustomStringConvertible協議時,發生了奇怪的事情-花費的時間增加了3次(請參閱最后一行的經過時間)
distinct
phoneNumber
Person
CustomStringConvertible
我從不打印任何Person對象,因此看不到description var被訪問21000次的明顯原因。 當我沒有實現CustomStringConvertible協議時,結果如下:
description
性能下降的原因是什么?
我敢打賭,游樂場正在使用description屬性將其顯示在右側時間軸視圖的結果中。 嘗試在操場外跑步,看看會發生什么。
[英]Why CustomStringConvertible protocol not working for Int?
[英]Checking for protocol availability in Swift
[英]ObjC protocol Implementation in Swift
[英]Is it possible to hash a Swift protocol?
[英]Swift 2 - protocol delegate not called
[英]Swift selector to protocol function?
[英]Swift closure in protocol extension
[英]Protocol inheritance + delegates in Swift
[英]Swift Protocol in Framework
[英]Generic protocol Swift 4 error
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.