Yesterday a coworker told me during a debug session, that if you use grep -r is much faster as when using grep with case insensitive Flag (e.g grep -ri) . So the question is, is this so? And if so why does it cost so much to transform letters into upper/lowercase characters? Thanks in advance
Yesterday a coworker told me during a debug session, that if you use grep -r is much faster as when using grep with case insensitive Flag (e.g grep -ri) . So the question is, is this so?
Why not? Performing comparisons considering the case insensitivity is complex than the usual case-sensitive match.
To make you understand in simpler terms, consider this example:
If you have to perform word comparison, then the ASCII value can be simply matched; if case insensitivity is into consideration, then you've to consider toupper()/tolower(), and then perform check on them.
So, searching considering the case insensitivity is somewhat complicated than case-sensitive one, thus being somewhat slower. But, you won't be able to figure out the differences in simpler searches.
And if so why does it cost so much to transform letters into upper/lowercase characters?
As already mentioned above, you're using an extra function call to perform the search successfully, so it costs more as compared to an exact match.
At the end, it totally depends on the use-case what you want.