Skip to content

ripgrep: case insensitive search is faster than case sensitive search #2444

Answered by BurntSushi
lfreist asked this question in General
Discussion options

You must be logged in to vote

OK, so this is a somewhat intriguing example. The short answer for why you're seeing this behavior is because ripgrep does pretty sophisticated black magic called "literal optimizations." The reason why it's black magic is because they are basically a big bag of heuristics that usually work really well. In this case, both are pretty fast, but it is indeed somewhat unusual to see a case insensitive search so much faster than the case sensitive version.

I'll also note that GNU grep demonstrates a similar phenomenon here:

$ time LC_ALL=C grep -E "pat[t ]ern" 3-gb.txt -c
12564

real    3.026
user    2.747
sys     0.277
maxmem  8 MB
faults  0

$ time LC_ALL=C grep -E "pat[t ]ern" 3-gb.txt -c -…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@lfreist
Comment options

Comment options

You must be logged in to vote
1 reply
@lfreist
Comment options

Answer selected by lfreist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants