So here is a simple program
import java.util.Random;
class main {
public static void main(String[] args) {
int MAX_VALUE = 5_000_000;
long startTime = System.currentTimeMillis();
Random rand = new Random();
for (int i = 0; i < MAX_VALUE; i++) {
eulerDistance(rand.nextInt(),rand.nextInt(),rand.nextInt(),rand.nextInt());
}
long endTime = System.currentTimeMillis() - startTime;
System.out.print("Time takes: " + endTime);
}
static int eulerDistance(int x1, int x2, int y1, int y2) {
return (int) Math.sqrt(
Math.pow(((double) x2 - (double) x1), 2) +
Math.pow(((double) y2 - (double) y1), 2)
);
}
}
I just wanted to test Java vs Go speed running this, for 5 mil iterations java appx takes 0.5 seconds where as go 2-3 seconds and for 50 mil java is 2-3 seconds and didn't wait for go... was taking too long.... I know about java's JIT and have seen it speed things up but what is happening here ?? Its it skipping iterations as there is no use for the value or is it some super optimal code running ?