操做double大概是float的3倍的時間消耗。java
public class DoubleFloatComparation { public static void main(String args[]) { //double float comparation long start2 = System.nanoTime(); float f = 0f; for(int i = 0; i< Integer.MAX_VALUE; i++){ f += 0.1; } long end2 = System.nanoTime(); System.out.println(end2 - start2); long start3 = System.nanoTime(); double d = 0d; for(int i = 0; i< Integer.MAX_VALUE; i++){ d += 0.1; } long end3 = System.nanoTime(); System.out.println(end3 - start3); } }