🔒 Locked
[java] Q on java performance
Advertisement
Original Post
Well, you have an MMORPG called Runescape (www.runescape.com) which is 3d and runs in an applet. Also, I played DOOM-like & Quake3-like betas that have an excellent framerate. It comes down to one thing though: if you program good, your program will show it. If you program poorly, your program will show that, too.
Quote:
Original post by rayce
i'm using Deitel's Java 2 Training Course and i was wondering about how fast the language was, at least relatively. Can anyone tell me how good of a game it can make(name a real game so i can get the idea; preferably a FPS)?
Silly question, it doesn't make sense. Java ranges from extremely slow, to pretty decent speed, depending on which VM, interpreter and/or compiler you use.
The speed is determined by the code that ends up being executed on the CPU, and that is not Java. A good compiler will turn Java code into efficient machine code, a bad one won't. And some will turn it into bytecode that runs on a VM.
Anyway, as the others have said, you can do some pretty decent things in Java.
Quote:
Original post by Spoonbender Quote:
Original post by rayce
i'm using Deitel's Java 2 Training Course and i was wondering about how fast the language was, at least relatively. Can anyone tell me how good of a game it can make(name a real game so i can get the idea; preferably a FPS)?
Silly question, it doesn't make sense. Java ranges from extremely slow, to pretty decent speed, depending on which VM, interpreter and/or compiler you use.
The speed is determined by the code that ends up being executed on the CPU, and that is not Java. A good compiler will turn Java code into efficient machine code, a bad one won't. And some will turn it into bytecode that runs on a VM.
Anyway, as the others have said, you can do some pretty decent things in Java.
alright then; which ide is the best for java? i thought it was just an interpreted language...it can be compiled into machine code as well? so that means it does not need the VM to operate, like an .exe file?
Quote:
Original post by Spoonbender Quote:
Original post by rayce
i'm using Deitel's Java 2 Training Course and i was wondering about how fast the language was, at least relatively. Can anyone tell me how good of a game it can make(name a real game so i can get the idea; preferably a FPS)?
Silly question, it doesn't make sense. Java ranges from extremely slow, to pretty decent speed, depending on which VM, interpreter and/or compiler you use.
And, let's not forget, how you write your code. :)
As others have said, most of the performance is directly related to the quality of the code. There are plenty of apps written for small devices like cell phones that are written in Java. They perform quite well in most cases, especially considering the limitations that are placed on them.
As for an IDE to use check out this topic.
I personally prefer Eclipse because it's nice on Windows.
As for an IDE to use check out this topic.
I personally prefer Eclipse because it's nice on Windows.
The VERY generic answer is that Java code, relative to C++, is about 1.5 times slower. But this is a very minor difference--in comparison, PHP and Python (true interpreted languages) are over 100 times slower. (And yea I didn't pull this outta my rear, this is out of a book at least.)
Yes, there are compilers for Java which will turn your code into machine code, the only one I know of off the top of my head is gcj, which is part of gcc.
Quote:
Original post by Tebriel
The VERY generic answer is that Java code, relative to C++, is about 1.5 times slower. But this is a very minor difference--in comparison, PHP and Python (true interpreted languages) are over 100 times slower. (And yea I didn't pull this outta my rear, this is out of a book at least.)
Crap, this is going to be a long thread now.
Anyway, in addition to gcj (which seems to still have incomplete support for all of java's libraries), there are also tools that can just bundle the JRE with your app. So your distribution goes up by 14mb, and your users can just run a plain old .exe without needing to install anything.
To answer all the OP's questions and clear up a little FUD:
Java ranges in speed from approx. 50% of optimised C++ to exactly the same as C++. On rare and special occasions it's faster but the reality is that whatever you try doing is almost certain to actually be limited by the performance of the graphics card and your own understanding of algorithms. You should be able to write Doom3 of HL2 quality code in Java and see no significant slowdown to speak of. However this is likely so far beyond your current capabilities given the nature of your post that by the time you can do it everything will have moved on a generation ;)
If you want to compile direct to executable code you can use Excelsior JET which produces code which is easily the same speed as C++ and starts up in an instant unlike the only other competitors which are JVMs. Sun's Hotspot server VM is about the same speed as JET but takes far, far longer to boot up. I myself have used JET, and it does indeed rock, but there's no Mac OS support.
GCJ is the other native executable option but it's very immature and best avoided until it hits some kind of "stable complete release status".
On the VM front, IBM's VM is reckoned to start up faster and create code that often surpasses C++ but I seem to recall this was at the expense of memory consumption and it's a bugger to actually find the download for it. It is freely distributable like the Sun VMs, I think, but I may be wrong.
Cas :)
Java ranges in speed from approx. 50% of optimised C++ to exactly the same as C++. On rare and special occasions it's faster but the reality is that whatever you try doing is almost certain to actually be limited by the performance of the graphics card and your own understanding of algorithms. You should be able to write Doom3 of HL2 quality code in Java and see no significant slowdown to speak of. However this is likely so far beyond your current capabilities given the nature of your post that by the time you can do it everything will have moved on a generation ;)
If you want to compile direct to executable code you can use Excelsior JET which produces code which is easily the same speed as C++ and starts up in an instant unlike the only other competitors which are JVMs. Sun's Hotspot server VM is about the same speed as JET but takes far, far longer to boot up. I myself have used JET, and it does indeed rock, but there's no Mac OS support.
GCJ is the other native executable option but it's very immature and best avoided until it hits some kind of "stable complete release status".
On the VM front, IBM's VM is reckoned to start up faster and create code that often surpasses C++ but I seem to recall this was at the expense of memory consumption and it's a bugger to actually find the download for it. It is freely distributable like the Sun VMs, I think, but I may be wrong.
Cas :)
Quote:
tebriel said:
The VERY generic answer is that Java code, relative to C++, is about 1.5 times slower. But this is a very minor difference--in comparison, PHP and Python (true interpreted languages) are over 100 times slower. (And yea I didn't pull this outta my rear, this is out of a book at least.)
Hm, I really would like to know the name of that book. More so with the allegations that Java is faster than C++. Have any of you done a real life comparison of the 2 on various algorithms? Aside the fact that INTERPRETED CODE cannot run faster than clear machine code (except on dedicated hardware - where are those SUN Java wired cpus that we heard about a few years ago anyway?), most books give you only teoretical numbers. (Teory says, book-wise, that interpreted code is 5-20 times slower than compiled code. old book, of course, 4 year old, to be exact, but nevertheless a competent book). Compiled Java should not exist anyway, it is against Java's fundamental principle. But even if you "compile" the Java code into native code, you still do the same thing as an interpretor, perhaps optimized a bit. And JavaME apps. being fast? LMAO
And no, Doom, Half Life 3->20 will never be on Java, at least I hope not.
Take a look at Carmack's blog. New Doom RPG for Cellphones in... doh, C++ (BREW), not Java. I do not know about you, but I'd trust his choices, on programming at least.
Tudor Tihan
Quote:
Original post by rayce
alright then; which ide is the best for java? i thought it was just an interpreted language...it can be compiled into machine code as well? so that means it does not need the VM to operate, like an .exe file?
It is often interpreted (or compiled to bytecode, which is interpreted), but there are also compilers that just compile it straight to native code. And yeah, then you just get an .exe file.
Generally speaking though, Java is typically a bit slower. Nothing devastating, but it can get tricky if you try to do some kind of *really* high performance app. (A FPS should be possible. A FSP with Quake 4 graphics might be tricky)
I can't see any reason why Java would be faster than C++. When Java runs on a VM, it obviously carries some overhead which C++ is free for. As ttdeath said, it is impossible for interpreted code to run faster than machine code. Yes, the code may be optimized by a clever compiler/interpreter, but there's no reason why the same couldn't be done to C++.
When compiled, it's theoretically the same, but C++ has far more resources spent on compilers, so it can probably be assumed that they are more advanced and optimized.
But again, keep in mind that you can't talk about the "speed" of C++ either. There are some really lousy compilers out there, and some extremely optimized ones.
ttdeath: I don't see anyone in the post you quoted say Java should be faster than C++.
Spoonbender:
check princec's:
It appears to me that those rare occasions don't really happen in real life.
But hey, I haven't run all Java apps...
Tudor
check princec's:
Quote:
Java ranges in speed from approx. 50% of optimised C++ to exactly the same as C++. On rare and special occasions it's faster
It appears to me that those rare occasions don't really happen in real life.
But hey, I haven't run all Java apps...
Tudor
I recently was doing a C to java port and ran into a random number generator that when used to generate 1M random numbers took 30 minutes with MS's compiler and 30 seconds using Sun's jvm. The code is identical except that the C code uses uint64 and the java code uses the long data type. Because of this I now tell people that Java is hundredds of times faster than C.
Quote:
Original post by ttdeath
Hm, I really would like to know the name of that book. More so with the allegations that Java is faster than C++. Have any of you done a real life comparison of the 2 on various algorithms? Aside the fact that INTERPRETED CODE cannot run faster than clear machine code (except on dedicated hardware - where are those SUN Java wired cpus that we heard about a few years ago anyway?), most books give you only teoretical numbers. (Teory says, book-wise, that interpreted code is 5-20 times slower than compiled code. old book, of course, 4 year old, to be exact, but nevertheless a competent book). Compiled Java should not exist anyway, it is against Java's fundamental principle. But even if you "compile" the Java code into native code, you still do the same thing as an interpretor, perhaps optimized a bit.
Man, this paragraph is so full of false statements. Java regularly uses Just In Time compilation. So it runs compiled code.
Also here's a quote from the Java platform wiki entry:
Quote:
This allows the JIT compiler to target a specific host platform and hardware, even potentially optimizing the output code in different ways based on observations of the program's behaviour.
So Java does optimization at run time. C code doesn't. I think this is how Java can be "faster on rare and special occasions".
Also, here's another example of when Java can be faster:
There are two programmers working on the same problem, Adam and Bob. Adam uses C++ and finishes the problem in 50 hours. Bob uses Java and finishes the problem in 40 hours. Bob spends his extra 10 hours optimizing the code, and rewrites one of his algorithms to be O(n^2) instead of O(n^4). Bob wins. :D
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement