Comparison of search algorithms within text strings

Question:

I'm trying to implement the following algorithms for searching expressions inside text strings in Java: Knuth-Morris-Pratt (KMP), Brute-force, Boyer-Moore and Levenshtein

How could you show the similarity obtained to perform a comparison between the algorithms, and see which one offers better performance?

Answer:

You can use a profiler to test the execution time of the developed algorithms, or you can test the total execution time.

long start = System.currentTimeMillis();  
//SEU CÓDIGO... pode ser a instância de um objeto também  
long delay = System.currentTimeMillis() - start;  
System.out.println("O tempo de execução foi de: " + delay + " milissegundos");  
Scroll to Top