4 ms·
I'm actually wondering why they do not compare the lengths first, anyone know? To me that would seem like the first obvious optimization, do not run the charact
by tyfon 10y ago
I'm actually wondering why they do not compare the lengths first, anyone know?
To me that would seem like the first obvious optimization, do not run the character compare at all if the lengths are different.
- gizmo686 10y agoIf the strings are not equal, they still need to say which string is "smaller" (eg. comes first alphabetically).
- tyfon 10y agoWell, that explains it! :)
- vkjv 10y agoThis is lexical comparison (<, >, =) not just equality.
- maggit 10y agoIn addition to what has been said about lexicographic ordering, if the strings are large, say several kB (as they may well be), the entire operation would be dominated by memory latency. In this case it is much cheaper to read each string once, instead of going an extra pass just to find the length.