As a test to see how much faster .net is than java I wrote 2 small programs. One in java and one in vb.net. The source code can be found below. To my amazement java actually seems to be faster than .net about 10 times! I did not make any changes to the default optimalizations. Java did have some weird behavior in checking the value of a variable. A loop written as while(var) { count++; } will run forever even if var is changed to false elsewhere. As soon as a function is getting called from within the lopp this behavior disappears. It seems to be some not well thought through optimalization in the compiler. The results are as follows:
.NET (3 runs):
Itterations in 5 seconds: 916553
Actual time in ticks: 50076088
Actual time in ticks: 50076088
Itterations in 5 seconds: 906226
Actual time in ticks: 50076088
Note that the ticks value doesn't seem to have as high resolution as suggested else all three would have a different value. This does show the code has run for about 5 seconds on each run.
Java (3 runs):
Itterations in 5 seconds: 11708018
Actual time in ms: 5008
Actual time in ms: 5008
Itterations in 5 seconds: 11736566
Actual time in ms: 5008
.net code: PerformanceTest.vb
java code: PerformanceTest.java This results in 2 big questions from my side:
- Did I do something wrong?
- Why are all Java applications so terribly slow? If you have an answer to either question feel free to send an e-mail to niks at the domain name in your browser without the ipv6 part. I would love to discuss this.
