为什么数学运算 Math.sqrt(x*x+y*y) 比 Math.hypo(x,y) 快很多?
public class Teste {
public static void main(String[] args) {
long ta = System.currentTimeMillis();
for( double x=0,y=0; x<5000000; x++,y+=2 ){
double d = Math.sqrt(x*x+y*y);
}
long tb = System.currentTimeMillis();
System.err.println((tb-ta));
ta = System.currentTimeMillis();
for( double x=0,y=0; x<5000000; x++,y+=2 ){
double d = Math.hypot(x,y);
}
tb = System.currentTimeMillis();
System.err.println((tb-ta));
}
}