I was performing some test performance on an algorithm and noticed something weird. Maybe I am missing something here.
I first measure the time in milliseconde:
long startTime = System.currentTimeMillis();
x.sort(sortStringInput);
long endTime = System.currentTimeMillis();
and then in nanoseconde:
long startTime = System.nanoTime();
x.sort(sortStringInput);
long endTime = System.nanoTime();
The results are 437ms qnd 26366ns.
I am calling the same method so how can it be possible to get a result in ns which is way smaller than the one in ms. I know that 1 ms is 1 000 000 ns so 26366 is even smaller than 1 ms…
Thanks,
Are you sorting the same list twice? The second call will be extremely fast if the list is already sorted.