• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Another JAVA vs .NET

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

JAVA

[ June 13, 2002: Message edited by: Gregg Bolinger ]
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This isn't news so I'm moving it to Java performance.
in my opinion the results are the product of the optimizer compiler more than anything else.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AMD Athlon 950, 256MB (133MHz) RAM, and Windows 98
5 seconds
Jamie
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why you don't check delta time like:
long start = System.currentTimeMillis();
long deltaTimeMs = System.currentTimeMillis() - start;
It looks much more simple.
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
reply
    Bookmark Topic Watch Topic
  • New Topic