Here I'm trying to benchmark my distinct
function, which receive array of random objects and return distinct array, by removing duplicates by phoneNumber
attribute: The strange thing happens when I implement CustomStringConvertible
protocol for my Person
class - the time spent for the task increases 3 times (see the elapsed time in very last line)
I never print any Person
object so I don't see obvious reason for description
var being accessed for 21000 times. Here is the result when I'm not implementing the CustomStringConvertible
protocol:
What is the reason for the performance drop?
I bet the playground is using the description
property to display it in the results on the right side timeline view. Try running this outside of a playground and see what happens.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.