I've got quick question. Why is Javascript almost twice as fast as Java code in this snippet? Java code:
public class Main{
public static void main(String[] args){
long startTime = System.currentTimeMillis();
double sum = 0.0;
for(double i=1; i<=100000; i++){
for(double j=1; j<=10000; j++){
sum += i/j;
}
}
long endTime = System.currentTimeMillis();
System.out.println(sum + " [" + (endTime-startTime) + "ms]");
}
}
Javascript code:
console.time("func");
console.log(func());
console.timeEnd("func");
function func(){
let sum = 0.0;
for(let i=1; i<=100000; i++){
for(let j=1; j<=10000; j++){
sum += i/j;
}
}
return sum;
}
As I understand Java is supposed to be faster when it comes to calculations, so this is where java should beat node anytime. Can you give some examples as to where is java superior in terms of performance. Thanks