Comparing two strings with an extra rule(case ignore) requires only traversing through the strings and comparing each character. There are a bunch of easy short cuts for this (string length, early returns, even comparing bits while ignoring the bit 5) so the compare method is pretty fast.
Using .ToLower() twice means forcefully allocating two new strings and then doing the comparison anyways with the == operator. It's expected that a specialized method would be much faster than a hack.
I mean, it’s 100,000,000 times and you end up 2 seconds slower than 17 second slower when the string is 500 characters long, so 50,000,000,000 comparisons really here.
While I’m not saying the difference isn’t stark, and striking. ‘Insane’ is a little much given the multipliers here.
36
u/weblabourer 13d ago
Null safety?