I need to know how long my algorithm`s implementation is executed. What I do:
long m1 = System.currentTimeMillis();
bm.search(mediumtext, mediumpattern);
System.out.println(System.currentTimeMillis() - m1);
But with every new run for the same example, it shows different values. So far I got them in the range 23 to 29.
I tried also
long mediumtime = System.nanoTime();
bm.search(mediumtext, mediumpattern);
mediumtime = System.nanoTime() - mediumtime;
System.out.printf("Elapsed %,9.3f ms\n", mediumtime/1_000_000.0);
And the problem is the same. Why it shows totally different values for the same example?
Maybe there is a more exact and correct way to get execution time?