Java:
public class Speedtest {
/**
* @param args the command line arguments
*/
static double vorher;
static double nachher;
static double d1,d2,d3,d4;
static float f1,f2,f3,f4;
static double dErg;
static float fErg;
public static void main(String[] args) {
// TODO code application logic here
f1 = (float) Math.sqrt(3);
f2 = (float) Math.sqrt(5);
f3 = (float) Math.sqrt(7);
f4 = (float) Math.sqrt(10);
d1 = Math.sqrt(3);
d2 = Math.sqrt(5);
d3 = Math.sqrt(7);
d4 = Math.sqrt(10);
// float rechnung
vorher = System.currentTimeMillis();
fErg = (f2-f1)*(f2-f1) + (f4-f3)* (f4-f3);
nachher = System.currentTimeMillis()- vorher;
System.out.println("Float Time: " + fErg);
// double rechnung
vorher = System.currentTimeMillis();
dErg = (d2-d1)*(d2-d1) + (d4-d3)* (d4-d3);
nachher = System.currentTimeMillis()- vorher;
System.out.println("Double Time: "+ nachher);
}
}
Output:
run:
Float Time: 0.520833
Double Time: 0.0
BUILD SUCCESSFUL (total time: 0 seconds)
float ist 32bit, double 64bit und float ist langsamer? wieso?