3 ms·
Maybe it's a short string optimization in this case, because the docs say that dropFirst is O(n) https://developer.apple.com/library/prerelease/ios/documentatio
by fauigerzigerk 11y ago
Maybe it's a short string optimization in this case, because the docs say that dropFirst is O(n)
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Reference/Swift_CollectionType_Protocol/index.html https://developer.apple.com/library/prerelease/ios/documenta...
Or they have optimized it after writing the docs. In any event, there's a lot more going on than what is necessary to parse a float. But I guess that's OK if the goal is to have a clean and consistent high level API.
- mikeash 11y agoIn that context, n is the number of items being dropped, not the length of the collection.
- fauigerzigerk 11y agoI wonder what makes it so slow then. I'm looking forward to the day when we can look at the source code :)
- mikeash 11y agoWhere are you getting that it's slow?
- fauigerzigerk 11y agoIn my own little ad-hoc micro benchmark it is. That's why I suspected that there was copying going on, but there could be so many other reasons for it that it was probably a pointless exercise in the first place. [Edit] And I mean relatively slow (4x the C++ code), not absysmally slow. Not a big deal.
- mikeash 11y agoGotcha. Do you have optimizations on? If so, I'd guess it's just the overhead of the extra indirection, plus dropFirst does have to examine that first little bit of data to determine the grapheme cluster boundaries.
- fauigerzigerk 11y agoYes I've done a release build.