473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How much fast is C++ than Java?

I have an app in Java. It works fine. Some people say Java works as
fast as C. Is that true?

C can use assembly language programs. How much faster are they inplace
of calling general routines.

Can C++ directly acess the Registers.

Will the Computation 5-10 times faster than Java?

Is there any benchmark which tell us these things.

Bye
Sanny

C++ Experts Needed: http://www.getclub.com/Experts.php
Jun 27 '08 #1
7 3634

"Sanny" <so*******@hotmail.comwrote in message
news:9c**********************************@y18g2000 pre.googlegroups.com...
>I have an app in Java. It works fine. Some people say Java works as
fast as C. Is that true?
No. C will typically be about 5-10 times faster than the same application
written in Java, if the bottleneck is in code written in those languages.
That's an important point, because often the bottleneck is the rasteriser on
the grapj=hics card or something similar, in which case C will have no
advantage.

However it rarely matters on modern PCs. The screen now usually updates
within a frame, so for any interactive work either Java or C is acceptable.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jun 27 '08 #2
bl****@myrealbox.com <bl****@myrealbox.comwrites:
In article <1p*********************@bt.com>,
Malcolm McLean <re*******@btinternet.comwrote:
>>
"Sanny" <so*******@hotmail.comwrote in message
news:9c**********************************@y18g200 0pre.googlegroups.com...
>I have an app in Java. It works fine. Some people say Java works as
fast as C. Is that true?
No. C will typically be about 5-10 times faster than the same application
written in Java, if the bottleneck is in code written in those languages.
That's an important point, because often the bottleneck is the rasteriser on
the grapj=hics card or something similar, in which case C will have no
advantage.

In my (admittedly limited, but more than zero) experience, C
is indeed faster, but not by anything like a factor of 5 to 10.
I'm curious to know what kinds of applications, on what systems,
exhibit such dramatic differences. I just did a quick check
using a toy numerical-integration example for a class I teach,
and the Java version took about 2.9 seconds, while the C version
took about 1.6 seconds. This is on a reasonably fast Intel-based
It all depends on the applications and on how much time is spent in the
library functions. It really doesn't take a rocket scientist to realise
that C, written by a competent programmer, will generally be faster than
Java.

Jun 27 '08 #3
In article <ft**********@registered.motzarella.org>,
Richard <de***@gmail.comwrote:
bl****@myrealbox.com <bl****@myrealbox.comwrites:
In article <1p*********************@bt.com>,
Malcolm McLean <re*******@btinternet.comwrote:
>
"Sanny" <so*******@hotmail.comwrote in message
news:9c**********************************@y18g2000 pre.googlegroups.com...
I have an app in Java. It works fine. Some people say Java works as
fast as C. Is that true?

No. C will typically be about 5-10 times faster than the same application
written in Java, if the bottleneck is in code written in those languages.
That's an important point, because often the bottleneck is the rasteriser on
the grapj=hics card or something similar, in which case C will have no
advantage.
In my (admittedly limited, but more than zero) experience, C
is indeed faster, but not by anything like a factor of 5 to 10.
I'm curious to know what kinds of applications, on what systems,
exhibit such dramatic differences. I just did a quick check
using a toy numerical-integration example for a class I teach,
and the Java version took about 2.9 seconds, while the C version
took about 1.6 seconds. This is on a reasonably fast Intel-based

It all depends on the applications and on how much time is spent in the
library functions. It really doesn't take a rocket scientist to realise
that C, written by a competent programmer, will generally be faster than
Java.
Probably so (despite the occasional claims by Java advocates
about the magic that can be worked via JIT compiling). But -- a
factor of 5 or 10? That's entirely plausible if the Java runtime
system is strictly a byte-code interpreter, as I understand the
early implementations were, but these days most of them do that
JIT compiling to native code, and while compiling isn't free,
it seems to me that if the cost of compiling a class is amortized
over many calls to its methods ....

Well. I don't mean to incite a flame war here -- I use and like
both Java and C -- but .... I wouldn't disagree with "Java is
generally slower, sometimes by a lot", but "Java is generally 5
to 10 times slower" seems to me to be too strong a claim. But I
admit that my perception is based more on anecdote and hearsay
than careful research.

--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.
Jun 27 '08 #4
bl****@myrealbox.com wrote:
In article <ft**********@registered.motzarella.org>,
Richard <de***@gmail.comwrote:
>bl****@myrealbox.com <bl****@myrealbox.comwrites:
In article <1p*********************@bt.com>,
Malcolm McLean <re*******@btinternet.comwrote:

"Sanny" <so*******@hotmail.comwrote in message
news:9c**********************************@y18g2000 pre.googlegroups.com...
>I have an app in Java. It works fine. Some people say Java works
as
fast as C. Is that true?

No. C will typically be about 5-10 times faster than the same
application written in Java, if the bottleneck is in code written
in those languages. That's an important point, because often the
bottleneck is the rasteriser on the grapj=hics card or something
similar, in which case C will have no advantage.

In my (admittedly limited, but more than zero) experience, C
is indeed faster, but not by anything like a factor of 5 to 10.
I'm curious to know what kinds of applications, on what systems,
exhibit such dramatic differences. I just did a quick check
using a toy numerical-integration example for a class I teach,
and the Java version took about 2.9 seconds, while the C version
took about 1.6 seconds. This is on a reasonably fast Intel-based

It all depends on the applications and on how much time is spent in
the library functions. It really doesn't take a rocket scientist to
realise that C, written by a competent programmer, will generally be
faster than Java.

Probably so (despite the occasional claims by Java advocates
about the magic that can be worked via JIT compiling). But -- a
factor of 5 or 10? That's entirely plausible if the Java runtime
system is strictly a byte-code interpreter, as I understand the
early implementations were, but these days most of them do that
JIT compiling to native code, and while compiling isn't free,
it seems to me that if the cost of compiling a class is amortized
over many calls to its methods ....

Well. I don't mean to incite a flame war here -- I use and like
both Java and C -- but .... I wouldn't disagree with "Java is
generally slower, sometimes by a lot", but "Java is generally 5
to 10 times slower" seems to me to be too strong a claim. But I
admit that my perception is based more on anecdote and hearsay
than careful research.
In my experience I have found that Java programs are about 2 to 4 times
slower than equivalent C programs. However their start-up time is _far_
slower compared to their C counterparts, which may be one reason why
many people think they are 5 to 10 times slower. This is of course due
to the overhead of loading the VM and all the necessary classes.

Also speed isn't the only consideration. Java programs consume much more
memory than C or C++ programs. Each Java program, no matter how
trivial, must run with it's own instance of a VM, so if you run several
Java programs simultaneously, you'll find that virtual memory
consumption reaches very high levels, though I'll admit that physical
memory consumed is not so much, though still significantly larger than
what roughly equivalent C/C++ programs would take up.

Jun 27 '08 #5
On Apr 13, 5:23 am, santosh <santosh....@gmail.comwrote:
blm...@myrealbox.com wrote:
In article <ftqv65$n5...@registered.motzarella.org>,
Richard <de...@gmail.comwrote:
blm...@myrealbox.com <blm...@myrealbox.comwrites:
In article <1pKdnUM3IrV-A53VRVny...@bt.com>,
Malcolm McLean <regniz...@btinternet.comwrote:
"Sanny" <softta...@hotmail.comwrote in message

news:9c**********************************@y18g2000 pre.googlegroups.com...
I have an app in Java. It works fine. Some people say Java works
as
fast as C. Is that true?
No. C will typically be about 5-10 times faster than the same
application written in Java, if the bottleneck is in code written
in those languages. That's an important point, because often the
bottleneck is the rasteriser on the grapj=hics card or something
similar, in which case C will have no advantage.
In my (admittedly limited, but more than zero) experience, C
is indeed faster, but not by anything like a factor of 5 to 10.
I'm curious to know what kinds of applications, on what systems,
exhibit such dramatic differences. I just did a quick check
using a toy numerical-integration example for a class I teach,
and the Java version took about 2.9 seconds, while the C version
took about 1.6 seconds. This is on a reasonably fast Intel-based
It all depends on the applications and on how much time is spent in
the library functions. It really doesn't take a rocket scientist to
realise that C, written by a competent programmer, will generally be
faster than Java.
Probably so (despite the occasional claims by Java advocates
about the magic that can be worked via JIT compiling). But -- a
factor of 5 or 10? That's entirely plausible if the Java runtime
system is strictly a byte-code interpreter, as I understand the
early implementations were, but these days most of them do that
JIT compiling to native code, and while compiling isn't free,
it seems to me that if the cost of compiling a class is amortized
over many calls to its methods ....
Well. I don't mean to incite a flame war here -- I use and like
both Java and C -- but .... I wouldn't disagree with "Java is
generally slower, sometimes by a lot", but "Java is generally 5
to 10 times slower" seems to me to be too strong a claim. But I
admit that my perception is based more on anecdote and hearsay
than careful research.

In my experience I have found that Java programs are about 2 to 4 times
slower than equivalent C programs. However their start-up time is _far_
slower compared to their C counterparts, which may be one reason why
many people think they are 5 to 10 times slower. This is of course due
to the overhead of loading the VM and all the necessary classes.

Also speed isn't the only consideration. Java programs consume much more
memory than C or C++ programs. Each Java program, no matter how
trivial, must run with it's own instance of a VM, so if you run several
Java programs simultaneously, you'll find that virtual memory
consumption reaches very high levels, though I'll admit that physical
memory consumed is not so much, though still significantly larger than
what roughly equivalent C/C++ programs would take up.
Yeah, but of course you can compile java programs to native executable
code with Jet, and produce exe's that run at pretty much the same
speed as C/C++ ones (maybe slightly slower on average), and which
don't need the JRE.

So, the normal byte-code/VM implementation of Java programs is slower,
especially the start-up-time, but the language itself isn't
necessarily (or at least, not by much).
Jun 27 '08 #6
In article <ft**********@registered.motzarella.org>,
santosh <sa*********@gmail.comwrote:
bl****@myrealbox.com wrote:
In article <ft**********@registered.motzarella.org>,
Richard <de***@gmail.comwrote:
[ snip ]
It all depends on the applications and on how much time is spent in
the library functions. It really doesn't take a rocket scientist to
realise that C, written by a competent programmer, will generally be
faster than Java.
Probably so (despite the occasional claims by Java advocates
about the magic that can be worked via JIT compiling). But -- a
factor of 5 or 10? That's entirely plausible if the Java runtime
system is strictly a byte-code interpreter, as I understand the
early implementations were, but these days most of them do that
JIT compiling to native code, and while compiling isn't free,
it seems to me that if the cost of compiling a class is amortized
over many calls to its methods ....

Well. I don't mean to incite a flame war here -- I use and like
both Java and C -- but .... I wouldn't disagree with "Java is
generally slower, sometimes by a lot", but "Java is generally 5
to 10 times slower" seems to me to be too strong a claim. But I
admit that my perception is based more on anecdote and hearsay
than careful research.

In my experience I have found that Java programs are about 2 to 4 times
slower than equivalent C programs. However their start-up time is _far_
slower compared to their C counterparts, which may be one reason why
many people think they are 5 to 10 times slower. This is of course due
to the overhead of loading the VM and all the necessary classes.
Start-up time is indeed a significant factor.
Also speed isn't the only consideration. Java programs consume much more
memory than C or C++ programs. Each Java program, no matter how
trivial, must run with it's own instance of a VM, so if you run several
Java programs simultaneously, you'll find that virtual memory
consumption reaches very high levels, though I'll admit that physical
memory consumed is not so much, though still significantly larger than
what roughly equivalent C/C++ programs would take up.
Yes .... It seems to me, though, that it would be feasible for a
JVM implementation to make use of something like shared libraries
in the UNIX world, or DLLs in the Windows world, to reduce memory
use. Whether any actually do -- I guess this group isn't really
the place to ask, is it?

--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.
Jun 27 '08 #7
In article <f5**********************************@u12g2000prd. googlegroups.com>,
Robert S <ro*********@gmail.comwrote:
On Apr 12, 9:01 pm, blm...@myrealbox.com <blm...@myrealbox.comwrote:
In article <aMidnZ9wgNOpkZzVnZ2dneKdnZydn...@bt.com>,

Malcolm McLean <regniz...@btinternet.comwrote:
[ snip ]
In my (admittedly limited, but more than zero) experience, C
is indeed faster, but not by anything like a factor of 5 to 10.
[ snip ]
Try a routine that uses mutli-dimensional arrays, and calculates numbers
based on adjacent elements in each direction.
What you'll find is that the Java indexing rules are nothing like as
efficient, and you'll get quite a considerable slowdown. I must admit I
haven't done my own timings, this is based on hearsay.
I also am not quite interested enough to do my own experiments, at
least right now. Certainly it's plausible that multidimensional
array access isn't as fast, given that conceptually a Java
multidimensional array is an array of array objects.

Time spent accessing 3D arrays on a modest wintel laptop:

C: 301 ms, Java: 731 ms, Size: 250*250*250
C: 171 ms, Java: 430 ms, Size: 200*200*200
I ran your programs (size 250 only) on a modest Linux desktop and
got -- well, actually they're *not* similar results, but a difference
more in line with the original claim (5 to 10 times slower):

C: 128 ms
Java: 635 ms

I noticed, though, that your Java code includes the allocation
of the array in the time being measured. If I time just the
part of the code that changes the array, I get:

Java, computation only: 121 ms

Whether it's "fair" (whatever that means in context) to include
allocating the array for the Java program but not the C program --
I'm not sure. But it does seem like the difference in overall
runtime isn't related to array access.

I am a bit curious, though, about why you made the array a
global variable in your C program. ?

(I tried making it a local variable in main() and -- as best
I could tell, gcc optimized it out of existence! which makes
a certain amount of sense, since the values placed in the array
are never used. Changing the program to instead use the array
values as input to some meaningless computation got around that,
but I wondered whether you had a similar experience, or your
reason for making it global was something else.)
Which fits in with what I've read about recent benchmarking: Java is
around about 2 to 3 times slower than C at most things.

Nowhere near 5 - 10 times.

Dev-cpp source:

#include <stdio.h>
#include <stdlib.h>
#include <sys/timeb.h>

#define size 250
int a[size][size][size];

int main(int argc, char *argv[])
{
struct timeb time1, time2;
time_t TimeMS; /*millisecond difference*/
time_t TimeS; /*time in seconds*/
time_t Elapsed_MS; /*elapsed time, milliseconds*/

ftime(&time1); /* starting time */

int i, j, k;

for(i=0; i<size; i++)
for(j=0; j<size; j++)
for(k=0; k<size; k++)
{
a[i][j][k] = i + j + k;
}

ftime(&time2); /* ending time */

TimeS = time2.time - time1.time; /*difference in seconds*/
TimeMS = time2.millitm - time1.millitm; /*millisecond
adjustment*/

Elapsed_MS = TimeS*1000 + TimeMS; /*elapsed time,
milliseconds*/

printf("%ld, %ld\n", time2.millitm, time1.millitm);
printf("Elapsed time in ms is: %ld\n", Elapsed_MS);
system("PAUSE");
return 0;
}

Java:

class testCvsJava
{
public static void main(String args[])
{
long m1;
long m2;
m1 = System.currentTimeMillis();

int size = 250;
int a[][][] = new int[size][size][size];
int i, j, k;

for(i=0; i<size; i++)
for(j=0; j<size; j++)
for(k=0; k<size; k++)
{
a[i][j][k] = i + j + k;
}

m2 = System.currentTimeMillis();

System.out.println("Execution time, ms: " + (m2 - m1));
}
}

--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.
Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: bdinmstig | last post by:
Hi. I need an implementation of java.util.Comparator with the following features: 1. Given a (mutable) java.util.List instance of unspecified size at construction time. 2. That List instance...
13
by: Charles Handy | last post by:
How does FastCGI compare against java Apps running in java app servers like TomCat, Sun One, WebLogic and WebSphere? Is there a business case for switching from CGI to Java? Performance?...
18
by: Michele Simionato | last post by:
I posted this few weeks ago (remember the C Sharp thread?) but it went unnoticed on the large mass of posts, so let me retry. Here I get Python+ Psyco twice as fast as optimized C, so I would like...
0
by: Andre | last post by:
Hello, I am working on refactoring my companies search engine, and a critical component of the search is that the results be displayed very quickly. We have done enourmous work on making the...
4
by: Alexis Gallagher | last post by:
(I tried to post this yesterday but I think my ISP ate it. Apologies if this is a double-post.) Is it possible to do very fast string processing in python? My bioinformatics application needs to...
4
by: Jean-François Blais | last post by:
Many must have asked that question. I intend to write a few programs which will be CPU intensive. I know a little of Java. Would a language that yields native code, instead of bytecode perfrom much...
11
by: Olie | last post by:
This post is realy to get some opinions on the best way of getting fast comunication between multiple applications. I have scowered the web for imformation on this subject and have just found...
8
by: . | last post by:
What is the fast way for a fast implementation of Python? -- JavaScript implementation of Python http://groups.google.it/group/JSython/
8
by: Sanny | last post by:
I have a old Pentium 2.5 Ghz Machine I use for surfing Net. I am just curious to know how much faster are the Server Machines are. Say they are 8 Core/ 16 Core??? What is the Max cores Modern...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.