Sign in to follow this  

C++ V.S Java for game programming.

This topic is 2184 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[quote name='medv4380' timestamp='1327443572' post='4905906']
C is best if you're going for speed.
C++ has many of the same slowdowns as Java does now. In fact today Java7 is about as fast as C++.[/quote]Uh,[color=#0000ff] [sup][citation needed][/sup][/color]
I'd like to see a benchmark proving this, where it wasn't simply because someone had written [url="http://macton.smugmug.com/gallery/8936708_T6zQX#!i=593426709&k=ZX4pZ"]crappy C++[/url] code.
You should be able to get the same assembly out of a C and C++ solution to a problem...

Share this post


Link to post
Share on other sites
[quote name='medv4380' timestamp='1327444141' post='4905917']
[quote name='alnite' timestamp='1327441512' post='4905894']
If Windows doesn't ship with a JRE, then that's Windows fault, which is obvious since they are promoting .NET.
[/quote]

No Microsoft is forbidden from bundling a Java Virtual Machine with Windows due to being caught being evil. [url="http://en.wikipedia.org/wiki/Microsoft_Java_Virtual_Machine"]http://en.wikipedia....Virtual_Machine[/url]
[/quote]

They are forbidden from bundling their own incompatible JVM, They could license Oracles (But they don't want to do that, as the court case showed they intentionally made their version incompatible in an attempt to make many Java applets non portable and thus reduce the threat of crossplatform applications)

Share this post


Link to post
Share on other sites
[quote name='medv4380' timestamp='1327444141' post='4905917']
[quote name='alnite' timestamp='1327441512' post='4905894']
If Windows doesn't ship with a JRE, then that's Windows fault, which is obvious since they are promoting .NET.
[/quote]

No Microsoft is forbidden from bundling a Java Virtual Machine with Windows due to being caught being evil. [url="http://en.wikipedia.org/wiki/Microsoft_Java_Virtual_Machine"]http://en.wikipedia....Virtual_Machine[/url]
[/quote]
Interesting, especially the embrace, extend, extinguish strategy.

Is there any anti-trust law that's preventing Microsoft from installing the same JRE that's provided by Sun/Oracle (rather than creating their own)?

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1327449108' post='4905935']
[quote name='medv4380' timestamp='1327443572' post='4905906']
C is best if you're going for speed.
C++ has many of the same slowdowns as Java does now. In fact today Java7 is about as fast as C++.[/quote]Uh,[color=#0000ff] [sup][citation needed][/sup][/color]
I'd like to see a benchmark proving this, where it wasn't simply because someone had written [url="http://macton.smugmug.com/gallery/8936708_T6zQX#!i=593426709&k=ZX4pZ"]crappy C++[/url] code.
You should be able to get the same assembly out of a C and C++ solution to a problem...
[/quote]

Here: [url="http://shootout.alioth.debian.org/"]http://shootout.alioth.debian.org/[/url]

If you don't like the crappy C++ code of any of the implementations, I think there are ways for you to submit a better one. But C and C++ are pretty much the same in that comparison.

Share this post


Link to post
Share on other sites
[quote name='alvaro' timestamp='1327455861' post='4905964']Here: [url="http://shootout.alioth.debian.org/"]http://shootout.alioth.debian.org/[/url]
If you don't like the crappy C++ code of any of the implementations, I think there are ways for you to submit a better one. But C and C++ are pretty much the same in that comparison.[/quote]Yeah the C/C++ ones are almost the same, and Java is generally much more RAM heavy...
However, I just picked the "binary trees" test at random to look at the [url="http://shootout.alioth.debian.org/u64q/program.php?test=binarytrees&lang=gcc&id=7"]C[/url] and [url="http://shootout.alioth.debian.org/u64q/program.php?test=binarytrees&lang=gpp&id=6"]C++[/url] versions, and this isn't a benchmark of C vs C++ at all! It's actually a benchmark of [url="http://apr.apache.org/docs/apr/0.9/group__apr__pools.html"]Apache pools[/url] vs [url="http://www.boost.org/doc/libs/1_41_0/libs/pool/doc/interfaces/object_pool.html"]Boost pools[/url], seeing as the choice of memory pool API is the only significant difference between the two versions of the code.

You could say that APR is more idiomatic for C, and Boost is more idiomatic for C++ ([i]in which case, you're still benchmarking "idiomatic libraries" instead of benchmarking the actual languages[/i]), but both versions of the code are using malloc/free/sprintf, instead of their idiomatic equivalents... so this benchmark isn't at all valid as a way to compare languages, or even as a way to compare "typical" usage of languages!

Share this post


Link to post
Share on other sites
This should satisfy your benchmark source request, and it should give you an ample number of languages to do additional comparisons.
[url="http://shootout.alioth.debian.org/u32/java.php"]http://shootout.alio...rg/u32/java.php[/url]

First Java7 has vastly improved from Java6 but that's 5 years of updated given in 1 version.

Java 7 beats C++ and C in the the K-Nucliotide benchmark by 4 to 5 seconds.
[url="http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=java&lang2=gcc"]http://shootout.alio...=java&lang2=gcc[/url]
Java 7 beats C++ in the fasta benchmark by ~1 second but loses to C by .1 seconds
[url="http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=java&lang2=gpp"]http://shootout.alio...=java&lang2=gpp[/url]

C flat out wins or nearly ties vs C++ in everything except the K-Nucliotide test
[url="http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=gcc&lang2=gpp"]http://shootout.alio...g=gcc&lang2=gpp[/url]

C when written properly beats C++ hands down.
The drawback of C is really that some more complex tasks are a pain to write without objects.

Java's main drawback is usually memory, but it's not as bad as most people think. Sure you have some where the Binary-Tree test ends up with Java taking nearly 5x the amount of memory C does, and on even small tests it still has to load a 10-15 meg virtual machine. However, somethings like the reverse complement test it takes nearly the same amount of memory as C does.

Java also attracted every programmer who was incapable of managing memory properly in C and C++ so there are a lot of bad memory structures out their in Java because at least it doesn't do the delayed crash thing C and C++ does when you mess with the memory the wrong way. Just because java has a garbage collector doesn't mean you can ignore memory, but that's what a lot of Java programmers do.

Share this post


Link to post
Share on other sites
For the love of all things holy,

[size=7]WHO CARES?[/size]

[size=3]You can't even benchmark a language. You can only benchmark a particular implementation of a language and a particular usage of that language, both of which are highly sensitive to change (use a different language implementation or a different programmer, and BAM! all the numbers change).[/size]

[size=3]Can we please, please let this thread die?[/size]

Share this post


Link to post
Share on other sites
[quote name='medv4380' timestamp='1327468097' post='4906005']
This should satisfy your benchmark source request, and it should give you an ample number of languages to do additional comparisons.
[url="http://shootout.alioth.debian.org/u32/java.php"]http://shootout.alio...rg/u32/java.php[/url]

First Java7 has vastly improved from Java6 but that's 5 years of updated given in 1 version.

Java 7 beats C++ and C in the the K-Nucliotide benchmark by 4 to 5 seconds.
[url="http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=java&lang2=gcc"]http://shootout.alio...=java&lang2=gcc[/url]
Java 7 beats C++ in the fasta benchmark by ~1 second but loses to C by .1 seconds
[url="http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=java&lang2=gpp"]http://shootout.alio...=java&lang2=gpp[/url]

C flat out wins or nearly ties vs C++ in everything except the K-Nucliotide test
[url="http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=gcc&lang2=gpp"]http://shootout.alio...g=gcc&lang2=gpp[/url]

C when written properly beats C++ hands down.
The drawback of C is really that some more complex tasks are a pain to write without objects.

Java's main drawback is usually memory, but it's not as bad as most people think. Sure you have some where the Binary-Tree test ends up with Java taking nearly 5x the amount of memory C does, and on even small tests it still has to load a 10-15 meg virtual machine. However, somethings like the reverse complement test it takes nearly the same amount of memory as C does.

Java also attracted every programmer who was incapable of managing memory properly in C and C++ so there are a lot of bad memory structures out their in Java because at least it doesn't do the delayed crash thing C and C++ does when you mess with the memory the wrong way. Just because java has a garbage collector doesn't mean you can ignore memory, but that's what a lot of Java programmers do.
[/quote]

You have to remember that it is still not a language benchmark, its a benchmark of various benchmark programs for a set of language implementations and while it does give you an idea of how fast something can be done with a specific implementation you really have to look at the code to see why the results are the way they are. (the C(GCC) implementation of binary trees for example uses OpenMP for parallell for loops while the Java implementation is singlethreaded.
For the K-Nucliotide benchmark both Java and C have multithreaded implementations but use fairly different approaches to the multithreading itself (Which has a huge impact, I'm guessing that the Java version wins simply due to the difference in threading methods used (Writing safe and well performing multithreaded code is alot easier in Java than it is in C))

C has both the fastest and the slowest implementations in alot of the tests, (CINT being the big loser and GCC usually the winner (both are C implementations)).

Performance have very little to do with the language (Allthough Javas fairly strict precision requirements does give it a disadvantage on platforms such as x86 and ARM for some operations), the code you write will always be the most important part followed by the quality of the compiler/VM/runtime you use to build/run the application.

Share this post


Link to post
Share on other sites
Sign in to follow this