I measured time to execute some codes. I see that static method is fast and synchronized method is slow.


result

     second process
0.377192935 empty loop
0.291664212 publicEmptyMethod
0.303606105 protectedEmptyMethod
0.286344766 emptyMethod
0.314491063 privateEmptyMethod
0.153063679 staticEmptyMethod
0.316276520 finalEmptyMethod
2.460220468 synchronizedEmptyMethod
0.280653043 strictfpEmptyMethod
0.331532345 Math.max(i,j)
0.331514772 inlined Math.max(i,j)
0.473257116 non static version of Math.max(i,j)

source code

import org.junit.Test;

public class TimeOfProcessOfMethod {
@Test
public void test0() {
int n = 10000;
System.out.format("%11s %s\n", "second", "process");
System.out.format("%.9f empty loop\n", emptyLoop(n));

System.out.format("%.9f publicEmptyMethod\n", publicEmptyMethod(n * n));
System.out.format("%.9f protectedEmptyMethod\n", protectedEmptyMethod(n * n));
System.out.format("%.9f emptyMethod\n", emptyMethod(n * n));
System.out.format("%.9f privateEmptyMethod\n", privateEmptyMethod(n * n));
System.out.format("%.9f staticEmptyMethod\n", staticEmptyMethod(n * n));
System.out.format("%.9f finalEmptyMethod\n", finalEmptyMethod(n * n));
System.out.format("%.9f synchronizedEmptyMethod\n", synchronizedEmptyMethod(n * n));
System.out.format("%.9f strictfpEmptyMethod\n", strictfpEmptyMethod(n * n));

System.out.format("%.9f Math.max(i,j)\n", MathMax(n));
System.out.format("%.9f inlined Math.max(i,j)\n", MathMaxInline(n));
System.out.format("%.9f non static version of Math.max(i,j)\n", MathMaxNonStatic(n));
}

private double emptyLoop(int n) {
long start = System.nanoTime();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
}
}
return (System.nanoTime() - start) * 1e-9;
}

private double publicEmptyMethod(int n) {
long start = System.nanoTime();
for (int i = 1; i <= n; i++) {
publicEmptyMethod();
}
return (System.nanoTime() - start) * 1e-9;
}

public void publicEmptyMethod() {
}

private double emptyMethod(int n) {
long start = System.nanoTime();
for (int i = 1; i <= n; i++) {
emptyMethod();
}
return (System.nanoTime() - start) * 1e-9;
}

void emptyMethod() {
}

private double protectedEmptyMethod(int n) {
long start = System.nanoTime();
for (int i = 1; i <= n; i++) {
protectedEmptyMethod();
}
return (System.nanoTime() - start) * 1e-9;
}

protected void protectedEmptyMethod() {
}

private double privateEmptyMethod(int n) {
long start = System.nanoTime();
for (int i = 1; i <= n; i++) {
privateEmptyMethod();
}
return (System.nanoTime() - start) * 1e-9;
}

private void privateEmptyMethod() {
}

private double staticEmptyMethod(int n) {
long start = System.nanoTime();
for (int i = 1; i <= n; i++) {
staticEmptyMethod();
}
return (System.nanoTime() - start) * 1e-9;
}

static void staticEmptyMethod() {
}

private double finalEmptyMethod(int n) {
long start = System.nanoTime();
for (int i = 1; i <= n; i++) {
finalEmptyMethod();
}
return (System.nanoTime() - start) * 1e-9;
}

final void finalEmptyMethod() {
}

private double synchronizedEmptyMethod(int n) {
long start = System.nanoTime();
for (int i = 1; i <= n; i++) {
synchronizedEmptyMethod();
}
return (System.nanoTime() - start) * 1e-9;
}

synchronized void synchronizedEmptyMethod() {
}

private double strictfpEmptyMethod(int n) {
long start = System.nanoTime();
for (int i = 1; i <= n; i++) {
strictfpEmptyMethod();
}
return (System.nanoTime() - start) * 1e-9;
}

strictfp void strictfpEmptyMethod() {
}

private double MathMax(int n) {
long start = System.nanoTime();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int a = Math.max(i, j);
}
}
return (System.nanoTime() - start) * 1e-9;
}

private double MathMaxInline(int n) {
long start = System.nanoTime();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int a = (i >= j) ? i : j;
}
}
return (System.nanoTime() - start) * 1e-9;
}

private double MathMaxNonStatic(int n) {
long start = System.nanoTime();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int a = max(i, j);
}
}
return (System.nanoTime() - start) * 1e-9;
}

private int max(int i, int j) {
return (i >= j) ? i : j;
}

}