Java indexOf function more efficient than Rabin-Karp? Search Efficiency of Text

后端 未结 7 545
面向向阳花
面向向阳花 2020-12-20 11:47

I posed a question to Stackoverflow a few weeks ago about a creating an efficient algorithm to search for a pattern in a large chunk of text. Right now I am using the St

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-20 12:45

    Here is the source to java.lang.String. indexOf is line 1770.

    My suspicion is since you are using it on such a short input string, the extra overhead of the Rabin-Karp algorithm over the seemly naive implementation of java.lang.String's indexOf, you aren't seeing the true performance of the algorithm. I would suggest trying it on a much longer input string to compare performance.

提交回复
热议问题