After reading the JAVA Pet Store Post in this forum, I had e-mailed an associate the links arguing both sides of JAVA and .NET. My associate is a .NET fanatic as I am a JAVA fanatic. He decided to challenge me. He wrote a program that calls an empty function 500 million times using VB.NET and it took 6 seconds from start to finish. He then wanted me to do the same thing in JAVA, so I did. 2.6 seconds. HA. We are both running Dell GX240 1.7 GHz 256MB RAM with Windows XP. Below is his code and my code. I challenge anyone else to do the same thing and see what the results are. The reason I find this so interesting is that these programs are so simple and so basic, I honestly thought that a BINARY program would out do a BYTECODE program. VB.NET
[ June 13, 2002: Message edited by: Gregg Bolinger ]
Just for kicks I wrote this in C. It took about 18 secs. In Java, 6 (7 when I commented out the method call...). So I went back to C and removed the method call, and low and behold a little less than 6 seconds. Then in C with the call and -O3 -- less than 3 seconds. In Java with -O -- 5 The moral/bad news: the speed of something like this seems to be a function of how much compiler optimizing is done by default, not of instruction execution speed. Since you will rarely be calling empty functions over and over, this particular difference doesn't seem significant.
How is that bad news? I am in no way saying that JAVA is faster than .NET by our little test. I especially would never say it is faster than C. I was saying that in this instance, it is faster. And I agree that it has a lot to do with compiler optimization, but isn't that part of it? I mean, if it is a compiler optimization issue, then we could deduce that JAVA has a better "shipped with" compiler than .NET? I am not stating that as fact, but that could be deduced. I would like to see the C code you wrote and would like to know what compiler you used for C. I always use the GNU compiler on a Linux platform. I am going to write my own tonight and see if I get similar results. I hope I get to see others results regarding this issue. Also include the computer specs you are doing this experiment with.
I confess I don't actually know how to time stuff in C, so I did it roughly by stopwatch. Gcc for cygwin on Windows 98 (about 5-600 MHz I think + 128 megs RAM).
I assume that any production build of software will turn on whatever optimizations are applicable. I suppose I assume too much . I don't know what the VB.NET optimizer can do when you let it take control. Maybe you should try an optimized comparison.
Actually Java is not running bytecodes. Only the first pass after which the JIT or the new version of that will take over and you will be executing maching code. Try it with the JIT on vs. Off. (or whatever the JIT is called these days)
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop