iOS 关于字符串Hash和isEqual效率的对比

因为不知道里面是怎么实现的,做了个小实验对比了一下,实验结果发现这两个没有什么区别
其实我感觉isEqual应该就是根据hash来判断的

if (self == object) elif self.hash == object.hash
实验数据
60 length        in  0.000000 ms
60 length        in  0.000954 ms
60 length        in  0.000000 ms
60 length        in  0.000000 ms
60 length        in  0.001073 ms
60 length        in  0.000954 ms
60 length        in  0.000954 ms
60 length        in  0.000000 ms
60 length        in  0.000000 ms
60 length        in  0.000000 ms

60 length        in 0.000000 ms
60 length        in 0.000000 ms
60 length        in 0.000000 ms
60 length        in 0.000954 ms
60 length        in 0.000954 ms
60 length        in 0.000000 ms
60 length        in 0.000954 ms
60 length        in 0.000000 ms
60 length        in 0.000000 ms
60 length        in 0.000000 ms
----------^0-----------
600 length       in  0.000000 ms
600 length       in  0.001073 ms
600 length       in  0.000000 ms
600 length       in  0.002027 ms
600 length       in  0.001073 ms
600 length       in  0.000954 ms
600 length       in  0.000000 ms
600 length       in  0.000954 ms
600 length       in  0.000000 ms
600 length       in  0.000954 ms

600 length       in 0.000000 ms
600 length       in 0.000000 ms
600 length       in 0.000000 ms
600 length       in 0.000000 ms
600 length       in 0.000000 ms
600 length       in 0.000000 ms
600 length       in 0.000000 ms
600 length       in 0.000000 ms
600 length       in 0.000000 ms
600 length       in 0.000000 ms
----------^1-----------
6000 length      in  0.000000 ms
6000 length      in  0.000000 ms
6000 length      in  0.000000 ms
6000 length      in  0.001073 ms
6000 length      in  0.000000 ms
6000 length      in  0.001073 ms
6000 length      in  0.000000 ms
6000 length      in  0.000000 ms
6000 length      in  0.000000 ms
6000 length      in  0.000954 ms

6000 length      in 0.000954 ms
6000 length      in 0.000000 ms
6000 length      in 0.000000 ms
6000 length      in 0.000000 ms
6000 length      in 0.000000 ms
6000 length      in 0.000000 ms
6000 length      in 0.000000 ms
6000 length      in 0.000954 ms
6000 length      in 0.000000 ms
6000 length      in 0.000000 ms
----------^2-----------
60000 length         in  0.000954 ms
60000 length         in  0.000954 ms
60000 length         in  0.000000 ms
60000 length         in  0.000000 ms
60000 length         in  0.000954 ms
60000 length         in  0.000000 ms
60000 length         in  0.000000 ms
60000 length         in  0.000000 ms
60000 length         in  0.001073 ms
60000 length         in  0.000954 ms

60000 length         in 0.000954 ms
60000 length         in 0.000000 ms
60000 length         in 0.000000 ms
60000 length         in 0.000000 ms
60000 length         in 0.000000 ms
60000 length         in 0.000000 ms
60000 length         in 0.000000 ms
60000 length         in 0.000000 ms
60000 length         in 0.000000 ms
60000 length         in 0.000000 ms
----------^3-----------
600000 length        in  0.001073 ms
600000 length        in  0.000000 ms
600000 length        in  0.000954 ms
600000 length        in  0.001073 ms
600000 length        in  0.000000 ms
600000 length        in  0.000000 ms
600000 length        in  0.000000 ms
600000 length        in  0.001073 ms
600000 length        in  0.000954 ms
600000 length        in  0.000000 ms

600000 length        in 0.000000 ms
600000 length        in 0.000000 ms
600000 length        in 0.000954 ms
600000 length        in 0.000000 ms
600000 length        in 0.000000 ms
600000 length        in 0.000000 ms
600000 length        in 0.000000 ms
600000 length        in 0.000000 ms
600000 length        in 0.000954 ms
600000 length        in 0.000000 ms
----------^4-----------
6000000 length       in  0.005007 ms
6000000 length       in  0.000000 ms
6000000 length       in  0.001073 ms
6000000 length       in  0.000000 ms
6000000 length       in  0.000000 ms
6000000 length       in  0.000000 ms
6000000 length       in  0.000954 ms
6000000 length       in  0.000000 ms
6000000 length       in  0.001073 ms
6000000 length       in  0.000000 ms

6000000 length       in 0.002027 ms
6000000 length       in 0.000000 ms
6000000 length       in 0.000000 ms
6000000 length       in 0.000954 ms
6000000 length       in 0.001073 ms
6000000 length       in 0.001073 ms
6000000 length       in 0.000000 ms
6000000 length       in 0.000000 ms
6000000 length       in 0.000000 ms
6000000 length       in 0.000000 ms
----------^5-----------

你可能感兴趣的:(iOS 关于字符串Hash和isEqual效率的对比)