• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which is faster : C or Java

 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to me C should be fast,but through results on google i am not clear which one of two is faster and why??Also tell about overall performance of a C program and a java program.kindly let me know..
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java unfortunately still has a bad reputation with regard to speed, which is completely undeserved.

Ten years ago, when we didn't have a sophisticated JIT (Just-In-Time) compiler in the JVM and (almost) all bytecode had to be interpreted while the program ran, yes, Java was slow. I'm talking about Java version 1.0 and 1.1 here.

Today, Java is not slow at all. Recently I picked up some C++ again (after having been programming almost exclusively in Java for the last 5 or 6 years). I wrote a small ray tracing program, which is very computation-intensive, in Java and in C++. To get the C++ program to run as fast as the Java program, I had to carefully set the optimization options on the C++ compiler.

So if someone tells you that Java is slow (slower than C or C++), ask him or her to prove it to you. Most likely the person is just repeating what he or she heard from others, without any proof.
 
Prashant kumar Singh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can easily understand that which one is fast.First C is Hardware friendly language.and java is User friendly.And java uses an interface in between user and Machine is Bytecode.But in begining age of java, it was very slow.But in this age, means java5, java is better in speed.it also depends upon arctitecture of Virtual machine.Some jvm works very fast like Jrockit.

Some people may say that C is more friendly to hardware than java. So C is fast. But it was true in past .But at this time Java is betterthats why all big projects are based on java concept.
Thats all

thanks
Prashant singh
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our performance forum...
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question really can't be answered. Both C and Java are compiled to machine code (just at different times - C at compile time, Java at runtime). Which program will be faster will depend on what machine code is produced - which depends on both

- what the source code looks like, and
- what program (C-Compiler/Java Virtual Machine) you use to generate machine code from it

Actually it could be argued that conceptually the JVM has two advantages:

- it can perform additional runtime analysis of the program to further optimize it, and
- it knows *exactly* what platforms it runs on, being able to perform special optimizations for that platform
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Performance issues between C applications and Java applications have more to do with the environment than the program itself. You can get both of them to do pretty much the same thing, in the same amount of time. At least that has been my experience.

Furthermore, Java often runs on the server-side. People complaining about Java being slow are likely complaining about the slowness of an internet connection, or poor use of connectoin pooling by an application server, none of which has any relationship to the execution of a Java program itself.

-Cameron McKenzie
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at this blog entry:

http://scienceblogs.com/goodmath/2006/11/the_c_is_efficient_language_fa.php

Basically the writer says that for applications where it matters (to him), Java and C both run equally as fast but other languages are faster.

So if you're looking for a single answer to your question, then this reference says that they're both equally fast. Of course it is pointless to provide a single answer since it really depends on what you want these Java or C programs to do.
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aperf1

aperf2

Does this make sense?

G.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Guy Allard:
aperf1

aperf2

Does this make sense?

G.


Not to me, but I may just be dumb. Care to elaborate?
 
Neerav Narielwala
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see the below link which tells us C vs Java detais :
http://www.cs.princeton.edu/introcs/faq/c2java.html
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Neerav Narielwala:
Please see the below link which tells us C vs Java detais :
http://www.cs.princeton.edu/introcs/faq/c2java.html


Not a word about performance, though...
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

thanks to Paul for his link (scienceblogs).

The huge difference between older and new Java compilers pointed there was really surprising.

And you made me think about FORTRAN again...

Bu.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is faster?

Like, if I needed to hire 10 programmers, would it be faster to find 10 young programmers that know C++, or 10 young programmers that know Java?

Or if I had a problem, which would I likely get faster support?

Or which one, C++ or Java, makes it faster to create a transactional web based application, such as J2EE or CORBA?

Hmmmmm. Which one is faster? I think Java.

And the JIT compiler means Java is no slouch at runtime, either.

-Cameron McKenzie
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Cameron W. McKenzie:
Which is faster?

Like, if I needed to hire 10 programmers, would it be faster to find 10 young programmers that know C++, or 10 young programmers that know Java?

Or if I had a problem, which would I likely get faster support?

Or which one, C++ or Java, makes it faster to create a transactional web based application, such as J2EE or CORBA?

Hmmmmm. Which one is faster? I think Java.

And the JIT compiler means Java is no slouch at runtime, either.

-Cameron McKenzie


Initially java was much slower , but now it has improved a lot.Though I have not done any sort of benchmarking as I do not know much of C/C++ , but I still think that java might be bit slower than C / C++.Though java has JIT but it only compiles qualifying code to native not all of the bytecode.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:


Not a word about performance, though...


Yea, Neerav seems to have a history of posting to be posting.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rahul Bhattacharjee:


Initially java was much slower , but now it has improved a lot.Though I have not done any sort of benchmarking as I do not know much of C/C++ , but I still think that java might be bit slower than C / C++.Though java has JIT but it only compiles qualifying code to native not all of the bytecode.


Wow, repeating what has already been said in this thread.

Seems to me that worrying about which is faster is a moot point. That's right, I used the word moot. Even if Java is slower at executing code than C/C++, I'd still choose Java for 98% of what I would need to do because most of the time, the execution of code is not the bottleneck in an application. Not to mention the speed of development time in Java compared to C/C++, which was already stated.
 
Martin Podrouzek
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fine day to you,

recently I attended a conference about Java in Antwerps. There was a notable speech of Brian Goetz about "Performance Myths in Java".

Here I link some articles of the Brian:
http://www-128.ibm.com/developerworks/views/java/libraryview.jsp?search_by=practice:

Just search for word "performance". I also recommend testing the code of Brian's. Have fun

Martin
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is moot. They are not comparable as such. This is not like asking which is faster C or Assembly. Both of those run directly on the CPU.

Java code on the other hand does not run directly on the CPU. It runs in a Java Virtual Machine. That JVM is typically written in C/C++.

The question then becomes, which 'c' program is faster. Your code, or the Sun/IBM JVM?
 
Pj Murray
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java has caught up with C++ in almost every runtime performance in almost every respect - except memory allocation.

So C++ is still a better choice if performance is a concern and there's large amounts of data to be handled.

Otherwise, Java is faster and therefore cheaper to develop with.
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Java has caught up with C++ in almost every runtime performance in almost every respect - except memory allocation.

So C++ is still a better choice if performance is a concern and there's large amounts of data to be handled."


Personally I thought Java memory allocation is better ...

http://www-128.ibm.com/developerworks/java/library/j-jtp09275.html

Basically my favourite story on this argument was an article in the C++ users group where they gave the same code to a java guru and C++ guru the Java implenation on a modern JVM finally out sped the C++ version. However the C++ guy went away twiddled the code and compiler settings and managed to surpass the Java with a days work, but it took a lot of work.

Having done a lot of both I'ed recommend java in most cases though there are still areas where C++ is the tool of choice just a lot less of them now, its no longer my generic language of choice .
 
Pj Murray
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chris Hurst:
[i]

Having done a lot of both I'ed recommend java in most cases though there are still areas where C++ is the tool of choice just a lot less of them now, its no longer my generic language of choice .


Yes - I think you've nailed it.
 
ws hong
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought c was fast, but now after I read the post,the idea changed,Thanks you above!
[ February 15, 2007: Message edited by: wshong wshong ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"wshong wshong",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read out the following faq of Performance issue between java and C using some standard BenchMarsk.

http://www.idiom.com/~zilla/Computer/javaCbenchmark.html

I hope this will answer the questions.
 
Pj Murray
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gregg Bolinger:


Wow, repeating what has already been said in this thread.



In fact, this whole thread is something of a time warp back several years.

I'm actually old enough to remember that before the Java versus C++ debate, there was a debate between the C and assembly language.

I wonder if a new major general programming language will emerge to we can repeat the cycle but this time having Java as the legacy language?
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by PJ Murray:
In fact, this whole thread is something of a time warp back several years.

I'm actually old enough to remember that before the Java versus C++ debate, there was a debate between the C and assembly language.
Even I am not old enough to remember that back in the dawn of history there was that same debate between assembly language and the basic machine instructions, as you can read here:

http://scienceblogs.com/goodmath/2007/03/sad_news_john_backus_has_died.php
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic