speed of java and c++

Write here if you have problems with your Java source code

Moderator: Board moderators

PMNOX
New poster
Posts: 49
Joined: Wed Feb 13, 2002 2:00 am
Location: Poland
Contact:

speed of java and c++

Post by PMNOX »

Hi
Does anybody know how many times on average is c++ faster than java?
Is 2, 10, 100 or maybe 1000 times??

veron
New poster
Posts: 29
Joined: Tue Jun 03, 2003 6:38 pm

Post by veron »

I think this two language is different on their purpose.So it should not so important that which one is fast.

But onething that most of the programmer in acm use C++,so they consider that c++ is faster.

I am not sure which one is faster between c++ and java.Is you....

xbeanx
Experienced poster
Posts: 114
Joined: Wed Jul 30, 2003 10:30 pm
Location: Newfoundland, Canada (St. John's)

Post by xbeanx »

C / C++ is definately faster than JAVA.

Just for comparison, one of my solutions to a problem here, written in JAVA, returned with a TLE (which means it ran for over 10 seconds).

I converted the program to C++, which was a line-by-line conversion, and it ran in ~0.05 seconds.

There was no difference in the program logic.

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

Just because it ran for over 10 seconds doesn't mean Java is that much slower, it could also be because you're reading inputs incorrectly...

Moni
Experienced poster
Posts: 202
Joined: Fri Mar 22, 2002 2:00 am
Location: Chittagong. CSE - CUET
Contact:

Re: speed of java and c++

Post by Moni »

PMNOX wrote:Hi
Does anybody know how many times on average is c++ faster than java?
Is 2, 10, 100 or maybe 1000 times??
I have heard it is 20 times faster than java but you can read this Xellent article :)

http://216.239.33.100/search?q=cache:J1 ... n&ie=UTF-8

Then what do you think?
ImageWe are all in a circular way, no advances, only moving and moving!

xbeanx
Experienced poster
Posts: 114
Joined: Wed Jul 30, 2003 10:30 pm
Location: Newfoundland, Canada (St. John's)

Post by xbeanx »

Larry wrote:Just because it ran for over 10 seconds doesn't mean Java is that much slower, it could also be because you're reading inputs incorrectly...
Even though JAVA is horribly slow, I still use it to solve ALL my problems on this site. There is only one that I could not solve using JAVA -- problem 110.

Problem 110 is the pascal sorting problem. My JAVA program output the correct answer, but ran in over 10 seconds. I converted it to C++ and it ran in less than 1 second.

To address the input parsing problem mentioned in the quote, the input was a single integer. I highly doubt that I failed to parse it correctly. I tried a test on the two programs, I timed them for all input: the time of the JAVA program grew exponentially while the time of the C++ program barely changed.

I think it may be because in my C++ program I was passing strings to functions as a pointer, while in JAVA it was passing the entire string.

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

Strings in Java are very expensive, as you keep making immutable objects, but if you know what to do, it isn't so bad..

veron
New poster
Posts: 29
Joined: Tue Jun 03, 2003 6:38 pm

Post by veron »

Again I want to say its totally a horrible reply from xbeanx because he make a decision on the basis of problem 110.

You cannot say that java is horribly slow.It depend on which situation which language demand.you say that using string on java it passes whole string. So you clearly know about that therefore why you use this.It totally a sorting problem.

Also there are many example that using JAVA is so much easy to solve rather than C++.

So JAVA have some drawback but you cannot ask it as a horrible slower language.

xbeanx
Experienced poster
Posts: 114
Joined: Wed Jul 30, 2003 10:30 pm
Location: Newfoundland, Canada (St. John's)

Post by xbeanx »

Vernon. I am not basing my judgement on one problem. In fact, I am basing my judgement on 7 years programming experience, as well as a University CS degree. I "stupified" my answer so that any inexperienced programmers would get some idea of a practical disadvantage.

If you want me to get technical, I can. There are theorems and proofs as to why JAVA is slower than C or C++. There is no dispute. There is not one person who can viably argue that JAVA is faster than C or C++. There is not one person who can argue that it is comparable.

Are you yourself suggesting that I made an incorrect statement by saying JAVA is slower? I would like to see your explanation of that.

And even after I rewrote my JAVA program to avoid strings altogether, the cost of recursion on a JVM is high and it still TLE. Again, the corresponding C++ program ran in less than a second.

I agree that there are situations where SOLVING a program in JAVA saves time, but there is never a situation where the RUN TIME of a java program will beat a C or C++ progam.

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

I think taht problem is : How fast is JVM used to judge our problems ... :)

Nearly in the past I read a comparision between many JVM's various producents .... and results are very intresting: one JVM could be 3-5 many faster than other ...

Java is slower than C/C++, I agree with that :) But I think, that in future this disproportion could be less and less :)

Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

veron
New poster
Posts: 29
Joined: Tue Jun 03, 2003 6:38 pm

Post by veron »

Hay again you misjudge my writings and post.It totally your headac that you are a CS student,that does'nt any matter for me.If you are CS student than you should reply the post with some proper behaviour.


But what you say in your previous post.You give an example PROBLEM-110,to proved JAVA is a HORRIBLE slower language.Yes,I am also agree with your comment but not agree with the word "HORRIBLE".If you think you are WELL KNOWNER on the program that ur matter not mine.

I am not so clear that how can you define that JAVA is horrible slower.Though it is slower but it is not horrible.
I am so much interest about your next post that how can you say that horrible.Become a CS student you have some comparison and mathodology between two language.I think you are so much angry on JAVA.WHY......

YES,i am fully agree with you that JAVA is slower than c++.But here is a condition about how fast is JVM used to judge our problem which was said by DM in his post.

Now I want to say about pointers.Yes,pointers is so much powerful and important features in c++.Nothing can change the power of pointers.But why we not take something different.
Mainly two causes:
1.For it insecureness.
2.inherently troublesome which is believed by java designers.

But that is real,perhaps the single biggest difference between java and c++.Though it is slow, but I belive that in the time it will be progress.

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

No one's saying Java will be faster than C/C++, but you really don't need to reiterate the fact that it's supposingly so many times faster - because it's simply not.

Besides, it's probably unfair to judge timing on the judge, as it compiles to C code anyhow, using GCJ, which probably haven't been optimized in who knows how long.. (or if they did, this judge takes no advantage of it). If they really use JVM, then that would be great.

And you really don't need to get technical, if you want to sound smart, just say so..

And I repeat, with better fonts, so maybe you'll understand:

"Just because it ran for over 10 seconds doesn't mean Java is that much slower.."

Never said it was faster, just that it shouldn't be that much slower... if it really was that much slower, would there be so many applications built on it?

xbeanx
Experienced poster
Posts: 114
Joined: Wed Jul 30, 2003 10:30 pm
Location: Newfoundland, Canada (St. John's)

Post by xbeanx »

Hey Larry.

Sorry for the repetition. However when someone attacks me, claiming my message is a "totally a horrible reply" I figure either

1) She didn't understand my original message; or
2) She is an asshole.

I thought I'd give vernon the benefit of the doubt and assume (1). That's why I repeated myself.

I agree that when using a JIT compiler java can be optimized and actually run half-fast. However, the whole philosophy of java revolves around architecture-independence, and thus its VM. Interpreting bytecode through a VM will never be as fast as running native code.

I believe most java users do in fact use the JDK, and subsequently the JRE. So in general, for most users, java will be slower.

Julien Cornebise
Experienced poster
Posts: 145
Joined: Sat Feb 23, 2002 2:00 am
Location: Paris, France
Contact:

Post by Julien Cornebise »

Larry wrote:Never said it was faster, just that it shouldn't be that much slower... if it really was that much slower, would there be so many applications built on it?
Hi

I just think that, when choosing a programming language for developing an application, many criterias are to be taken into account. Speed is only one of many : easiness of developpement, re-usability, existence of a much developed lib class (well, STL is good, that's true, though not always so standard), portability, and end user : with Java you easily do beautiful Playskool-like man-machine interfaces, so when developping an application for e.g. commercial vendors, you have to make it as easy as possible, so Java is here helpful I guess. All those factors might explain why so many appli are built on it (possibly including critical pieces of software developed in other language for efficiency).
Well, that's what I've been taught in one of my CS classes... ;-)

veron
New poster
Posts: 29
Joined: Tue Jun 03, 2003 6:38 pm

Post by veron »

Yeah,it's so much clear that you are a damm crazy talker....
You cannot able to understand your own post.But I am not trying to hurt anybody,if somebody feel bad I am sorry for that.

Really,its a crazy situation for me,not only I am,everyone say that damm JAVA is not fast than your c++.But what do you think yourself?Are you
understand my comment,or not?If you not then pls don't reply post and I am not so interest to carry on this debate.

But nevertheless I want to say your behave childnous and crazy,you must try to remember that I am not like to take any help and don't offer this type of word.

which I belive which I say.

Ofcourse there is important participation of JVM for runtime speed.Is you think JVM is not so stronge in its task.I think you have no clear view of JVM,what it can.Also I say that it's got some difficulties which is occur currently.

Now I want to say a common and basic problem of JVM.The basic difference of JVM and other compiler.
Most programming languages are compiled into machine code, which is interpreted directly by the CPU.In contrast, Java is compiledinto "bytecode" which is interpreted by a JVM. A Java virtual machine is a program which acts as a middleman between the Java code and the CPU.
It’s a common feature of VM is that, the use of the virtual machine allows Java programmers, in the words of Java's creators.
The various virtual machines are in different stages of development, and each has its own set of bugs. A program which executes properly on one VM, may have problems on another VM.
Most exciting and powerful capability is that you can write a program and debug anywhere as you like. As Java develops and stabilizes as a language, these problems should disappear, but currently this does create problems. What short of problems we face in our JVM, INDEPENDENT OR PRISONER IN A MISTERIOUS ISLAND?

That is common and one of biggest question for JVM.

Post Reply

Return to “Java”