Archived

This topic is now archived and is closed to further replies.

A Benchmark, C++ vs Java

This topic is 4914 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

http://www.kano.net/javabench/ I found this on google today, and I thought I would share. Any thoughts on this? I mean I always hear about how Java is _SO_ slow compared to C++. Please don''t turn this into a Java vs C++ flamewar.

Share this post


Link to post
Share on other sites
quote:
Original post by nakor
Please don''t turn this into a Java vs C++ flamewar.



um...perhaps if you didn''t want a flamewar you shouldn''t have posted an article titled: "The Java is Faster than C++ and C++ Sucks Unbiased Benchmark". how this cannot become a flamewar escapes me.

-me

Share this post


Link to post
Share on other sites
quote:
Please don''t turn this into a Java vs C++ flamewar.

Too late, you used "vs" in the title.

The guy that runs kano.net is a Java apologist, for what it''s worth.

Share this post


Link to post
Share on other sites
Java/C++ benchmarks are hardly worth the time it takes you to read them. People can always argue stats both ways or say they are unfair or just talk plain bullshit.

One way to test Java''s performance: Build an app using it and try it yourself. Experiance is worth a thousand benchmarks.

The Java/C++ perpetual-flamewar-machine has always been fueled by idiots with either little or inaccurate information. (Often both) What Java needs more than anything is someone have faith and prove that fast apps can be written by writing one.

Speaking of which, advert time: My Amateur Game Project

Share this post


Link to post
Share on other sites
This is almost turning into a flame war on how this is destined to turn into a flame war. The irony is bittersweet.

For future reference to everyone, just because you put "please don''t turn this into a flame war" at the bottom of your post doesn''t make you any less responsible when a flame war does begin You can''t feign innocence, the proof is in the pudding! Muahaha!

Share this post


Link to post
Share on other sites
quote:
Original post by zoggo
What Java needs more than anything is someone have faith and prove that fast apps can be written by writing one.

Speaking of which, advert time: My Amateur Game Project


Dude, your page is a poor advert; you could at least wait until you have some screen shots to show...

Share this post


Link to post
Share on other sites
I find benchmarks like this so funny. It was even linked to from an intro to soft eng course at the uni I went to (they teach java). The way academics talk you''d think all programs just consisted of algorithms you learn in 1st year university.

As some of the previous posters have said, show us a Java (GUI) application that runs as fast a native app and we''ll start believing you!! Why people think Java HAS to be fast in this department eludes me though, Java is great for what it does, and is great for server components etc.. For games and real time applications I''ll go c/c++ anyday.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It''s completely obvious that this guy has no idea how to program in C++...he couldn''t even decipher and fix errors listed by gcc for simple programs; how are we supposed to expect that he knows how to optimize a C++ program?

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
It''s completely obvious that this guy has no idea how to program in C++...he couldn''t even decipher and fix errors listed by gcc for simple programs; how are we supposed to expect that he knows how to optimize a C++ program?



Back stabber!
Only cowards hide behind "Anonymous Poster" posts to say anything they want to in a bad light! Besides, there''s no reason to brag that you know more about c++ than him. Give the poor guy a break, he just asked for a benchmark, not a FLAME-mark!


// Last Attacker \\---=( LA )=---// LA Extreme \\

ICQ Number : 120585863

E-mail: laextr@icqmail.com

Share this post


Link to post
Share on other sites
quote:
Dude, your page is a poor advert; you could at least wait until you have some screen shots to show...


Yea I know! Sorry, but I am still trying to recruit people. I have a number of volunteers now, but at the time of that post I was desparate for a new way of saying *bump*. Sorry for any harm done to the Java cause.

Share this post


Link to post
Share on other sites
Yeah, just reading that page makes me think that the person who made it might not be the most reliable source of information there is. On the other hand, he does have very pretty graphs...

Anyway, correct me if I''m wrong, but isn''t Java based entirely C with the added overhead of being an interpreted language? It seems to me that Java shouldn''t be any faster than C or C++ in any test.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Just tested the first one(ackermann) and well time reported the following:

simon@scorpio:~/dev/benchmarks$ time ./ackermann 12
Ack(3,12): 32765

real 0m4.398s
user 0m4.334s
sys 0m0.044s
simon@scorpio:~/dev/benchmarks$ time java ackermann 12
Ack(3,12): 32765

real 0m17.387s
user 0m17.126s
sys 0m0.126s
simon@scorpio:~/dev/benchmarks$

Benchmarks aren''t my thing so I won''t say anything just compiled them both and ran em. How he got the numbers he got I don''t really know, btw running suns own virtual machine 1.4.2.04 and gcc 3.3.

- Damage Incorporated.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Actually I have server as default.

- Damage Incorporated.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you''re using server VM, you should loop the benchmark code several times, because the server VM first lets the code be interpreted for a while and the compiles it with optimizations based on what it''s been doing so far. Loop it 10 times and time only the 10th loop (you probably can''t do this with the *n*x time command though). I know he doesn''t say that on the site; I have no idea how he got those numbers so small unless he switched machine to run the Java code.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
"Anyway, correct me if I''m wrong, but isn''t Java based entirely C with the added overhead of being an interpreted language? It seems to me that Java shouldn''t be any faster than C or C++ in any test."
In fact, modern JVM''s compile (at least some parts of) a Java program to native code after it starts running, so it''s not always interpreted. This is called Just In Time (JIT) compilation. The question is whether your JIT compiler is as good as your C++ compiler. If you ran the benchmark with JRE 1.0, it would probably be 10 times slower.

Share this post


Link to post
Share on other sites
The latest "hotspot" vm from Sun, picks the most used (hotspots) in code to JIT compile. This has the odd effect of meaning that loops will run slowly for the first few iterations and then, as hotspot realises its importance, it will be compiled to native machine code. Not only that, the loop doesn''t have to finish for the hotspot JIT to work, it can replace currently executing code with a JIT compiled version. Very clever.

Share this post


Link to post
Share on other sites
JITs convert the bytecode to machine code correct?
so that would make the game "non-cross platfrom". right?

so (going by this assumption) would the benchmark be more valid or correct if it was based on the bytecode produced by Java vs. the C++ object code (i guess it would be machine code)?

i hope i made sense....

Share this post


Link to post
Share on other sites
No, it converts the bytecode to the machine code of *the current platform*, *while it is running*. This is possible because the VM for each platform is programmed to be aware of the local machine code. Run the Java code on a Mac, it executes bytecode and then seamlessly compiles parts of it into PPC machine code, on the fly, substituting these bits into the execution path. Similarly on x86, creating x86 machine code.

I have no idea how they make all of that work, though.

FWIW, the C++ object files aren''t particularly cross-platform either.

Share this post


Link to post
Share on other sites
quote:
Original post by Zahlman
I have no idea how they make all of that work, though.


This book goes into quite some details on how the .NET JIT engine works. I assume the principles are pretty much the same for Java.

--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]

Share this post


Link to post
Share on other sites
Java VM''s are written mostly in C with some ASM thrown in.

Hence, there is absolutely no reason at all why a C / ASM should run slower than a Java program.

The obvious explanations exist for why the benchmarks were slower:

1.) The person doing the benchmarks is biased (somewhat likely)

2.) The person doing the benchmarks didn''t use ''equivilent'' algorithms for each program (highly likely)

3.) The benchmarks being used are too "simple" - that is, the JVM is capable of executing the generated bytecode (or machine code) with virtually no bytecode overhead, hence running at the exact same speed as native languages. Again, this should only provide for performance that is (at best) equivilent of the native code (very likely, as the VM''s are well designed for the most part).

4.) The guys writing the benchmarks are complete hacks and/or just aren''t anywhere near as good as the programmers writing the VM''s (also very likely).

The fastest execution you will EVER get is by compiling to native languages - period. You simply can''t get any faster, because this is the best the processor can do.

That isn''t to say that C#, VB, or Java aren''t "fast enough", because for many applications, they are. But to say that they''re "just as fast as" or even "faster than" C/C++ is a statement that only a very stupid individual would make.

Share this post


Link to post
Share on other sites