If you look, for example, at the Java function String.indexOf, it seems that they use brute force to match strings. You may wonder why this is so.
The reason is that in these algorithms some preliminary processing of the requests is performed, and this can be expensive (especially for BM if you use both arrays). Therefore, the strings you are searching must be large before KMP and BM can beet brute force.
There is always trade when using different algorithms, and when working with large strings, you can also consider indexing text instead of a query (for example, suffix trees). It can even be useful when you are dealing with new texts every time.
In my opinion, these algorithms are quite academic and useful only in special circumstances.
source share