class Timing{ public static void main2(String[] args){ long start; BBB b = new BBB(); AAA a = new AAA(); boolean h; start = System.currentTimeMillis(); for (int i = 0; i <100000000; i++) h = (b instanceof BBB); System.out.println("is kind of takes: " + (System.currentTimeMillis()-start)); start = System.currentTimeMillis(); for (int i = 0; i <100000000; i++) h = ((b != null) && (b.getClass() == a.getClass() )); System.out.println("getClass: " + (System.currentTimeMillis()-start)); a = null; System.out.println(a instanceof AAA); } public static void main(String[] args){ long start; Ball b1 = new Ball("Red"); Ball b2 = new Ball("Blue"); String s = "hello"; boolean h; start = System.currentTimeMillis(); for (int i = 0; i <10000000; i++) h = (b1.equals2(b2)); System.out.println("equals of takes: " + (System.currentTimeMillis()-start)); start = System.currentTimeMillis(); for (int i = 0; i <10000000; i++) h = b1.equals2(s); System.out.println("equals2: " + (System.currentTimeMillis()-start)); } }