I suspect that the profiler does not give you a true result, since it is trying to profile (and thus add to the head) such a trivial "method". Without a profile, Math.abs can be turned into a small number of machine code instructions, and you cannot do it faster than this.
I suggest you do a micro test to confirm this. I expect data loading to be an order of magnitude more expensive.
long a = 10, b = 6, c = -2, d = 3; int runs = 1000 * 1000 * 1000; long start = System.nanoTime(); for (int i = 0; i < runs; i += 2) { long r = Math.abs(i - a) - Math.abs(c - i); long r2 = Math.abs(i - b) - Math.abs(d - i); if (r + r2 < Integer.MIN_VALUE) throw new AssertionError(); } long time = System.nanoTime() - start; System.out.printf("Took an average of %.1f ns per abs-abs. %n", (double) time / runs);
prints
Took an average of 0.9 ns per abs-abs.
source share