PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > How much fast is C++ than Java?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How much fast is C++ than Java?

Réponse
 
LinkBack Outils de la discussion
Vieux 12/04/2008, 12h10   #1
Sanny
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 12/04/2008, 12h37   #2
Malcolm McLean
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How much fast is C++ than Java?


"Sanny" <softtanks@hotmail.com> wrote in message
news:9cfadb86-c03f-4964-96f3-b13020036b9b@y18g2000pre.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

  Réponse avec citation
Vieux 12/04/2008, 19h13   #3
blmblm@myrealbox.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How much fast is C++ than Java?

In article <1pKdnUM3IrV-A53VRVnyjgA@bt.com>,
Malcolm McLean <regniztar@btinternet.com> wrote:
>
> "Sanny" <softtanks@hotmail.com> wrote in message
> news:9cfadb86-c03f-4964-96f3-b13020036b9b@y18g2000pre.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
desktop-class machine running Linux, gcc, and Sun's Java. One of
my colleagues has done a couple of C++-versus-Java performance
comparisons using real code, and while the C++ versions are
invariably faster, the slowdown for the Java versions is usually
on the order of 10 to 25 percent (e.g., if the C++ version takes 1
minute, the Java version takes 1.1 to 1.25 minutes). There was one
exception -- a program that makes extensive use of trig functions,
which in Java are apparently (sometimes?) implemented in a way
that emphasizes portability over performance, or something. Now,
that's C++ and not C, but I have the impression from another
recent discussion in this group that C and C++ give comparable
performance.

Not saying you're wrong, Malcolm, just wondering why your
experience seems so different from mine. Early implementations
of Java were indeed quite slow, but my understanding is that most
current implementations do just-in-time compilation to native code,
and the results are pretty good.

> 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.


This is of course a good point!

--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.
  Réponse avec citation
Vieux 12/04/2008, 19h31   #4
Richard
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How much fast is C++ than Java?

blmblm@myrealbox.com <blmblm@myrealbox.com> writes:

> In article <1pKdnUM3IrV-A53VRVnyjgA@bt.com>,
> Malcolm McLean <regniztar@btinternet.com> wrote:
>>
>> "Sanny" <softtanks@hotmail.com> wrote in message
>> news:9cfadb86-c03f-4964-96f3-b13020036b9b@y18g2000pre.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.

  Réponse avec citation
Vieux 12/04/2008, 20h24   #5
Malcolm McLean
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How much fast is C++ than Java?


<blmblm@myrealbox.com> wrote in message
news:66cceuF2juskbU1@mid.individual.net...
> In article <1pKdnUM3IrV-A53VRVnyjgA@bt.com>,
> Malcolm McLean <regniztar@btinternet.com> wrote:
>>
>> "Sanny" <softtanks@hotmail.com> wrote in message
>> news:9cfadb86-c03f-4964-96f3-b13020036b9b@y18g2000pre.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
> desktop-class machine running Linux, gcc, and Sun's Java. One of
> my colleagues has done a couple of C++-versus-Java performance
> comparisons using real code, and while the C++ versions are
> invariably faster, the slowdown for the Java versions is usually
> on the order of 10 to 25 percent (e.g., if the C++ version takes 1
> minute, the Java version takes 1.1 to 1.25 minutes). There was one
> exception -- a program that makes extensive use of trig functions,
> which in Java are apparently (sometimes?) implemented in a way
> that emphasizes portability over performance, or something. Now,
> that's C++ and not C, but I have the impression from another
> recent discussion in this group that C and C++ give comparable
> performance.
>
> Not saying you're wrong, Malcolm, just wondering why your
> experience seems so different from mine. Early implementations
> of Java were indeed quite slow, but my understanding is that most
> current implementations do just-in-time compilation to native code,
> and the results are pretty good.
>

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.

Your code's bottleneck was probably the trig functions, which may have been
written in assembly even for the Java version.

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

  Réponse avec citation
Vieux 12/04/2008, 21h01   #6
blmblm@myrealbox.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How much fast is C++ than Java?

In article <aMidnZ9wgNOpkZzVnZ2dneKdnZydnZ2d@bt.com>,
Malcolm McLean <regniztar@btinternet.com> wrote:
>
> <blmblm@myrealbox.com> wrote in message
> news:66cceuF2juskbU1@mid.individual.net...
> > In article <1pKdnUM3IrV-A53VRVnyjgA@bt.com>,
> > Malcolm McLean <regniztar@btinternet.com> wrote:
> >>
> >> "Sanny" <softtanks@hotmail.com> wrote in message
> >> news:9cfadb86-c03f-4964-96f3-b13020036b9b@y18g2000pre.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
> > desktop-class machine running Linux, gcc, and Sun's Java. One of
> > my colleagues has done a couple of C++-versus-Java performance
> > comparisons using real code, and while the C++ versions are
> > invariably faster, the slowdown for the Java versions is usually
> > on the order of 10 to 25 percent (e.g., if the C++ version takes 1
> > minute, the Java version takes 1.1 to 1.25 minutes). There was one
> > exception -- a program that makes extensive use of trig functions,
> > which in Java are apparently (sometimes?) implemented in a way
> > that emphasizes portability over performance, or something. Now,
> > that's C++ and not C, but I have the impression from another
> > recent discussion in this group that C and C++ give comparable
> > performance.
> >
> > Not saying you're wrong, Malcolm, just wondering why your
> > experience seems so different from mine. Early implementations
> > of Java were indeed quite slow, but my understanding is that most
> > current implementations do just-in-time compilation to native code,
> > and the results are pretty good.
> >

> 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.

> Your code's bottleneck was probably the trig functions, which may have been
> written in assembly even for the Java version.


Nitpick: the code with the trig stuff is a colleague's not mine.

The initial Java version was much, much slower; profiling revealed
that a lot of time was being spent in the Java library trig
functions. I believe he ended up using JNI (Java Native Interface)
to call the C library functions, and that ed considerably.

There was a recent thread in comp.lang.java.programmer on this
subject, and while I didn't follow it carefully, I got the
impression that Java's library functions compare pretty well
with library functions in other languages on some architectures,
but not on others. I think the difficulty may be that the Java
standard imposes restrictions that rule out use of hardware
features other languages can and do make use of. That's vague,
I know, but maybe you also can extrapolate to imagine what some
of the issues might be -- I'm thinking that C leaves some things
unspecified so that implementations can do whatever works best
on particular platforms, and Java doesn't do that so much.

--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.
  Réponse avec citation
Vieux 12/04/2008, 21h16   #7
blmblm@myrealbox.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How much fast is C++ than Java?

In article <ftqv65$n5o$1@registered.motzarella.org>,
Richard <devr_@gmail.com> wrote:
> blmblm@myrealbox.com <blmblm@myrealbox.com> writes:
>
> > In article <1pKdnUM3IrV-A53VRVnyjgA@bt.com>,
> > Malcolm McLean <regniztar@btinternet.com> wrote:
> >>
> >> "Sanny" <softtanks@hotmail.com> wrote in message
> >> news:9cfadb86-c03f-4964-96f3-b13020036b9b@y18g2000pre.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.
  Réponse avec citation
Vieux 13/04/2008, 00h22   #8
Robert S
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How much fast is C++ than Java?

On Apr 12, 9:01 pm, blm...@myrealbox.com <blm...@myrealbox.com> wrote:
> In article <aMidnZ9wgNOpkZzVnZ2dneKdnZydn...@bt.com>,
>
>
>
> Malcolm McLean <regniz...@btinternet.com> wrote:
>
> > <blm...@myrealbox.com> wrote in message
> >news:66cceuF2juskbU1@mid.individual.net...
> > > In article <1pKdnUM3IrV-A53VRVny...@bt.com>,
> > > Malcolm McLean <regniz...@btinternet.com> wrote:

>
> > >> "Sanny" <softta...@hotmail.com> wrote in message
> > >>news:9cfadb86-c03f-4964-96f3-b13020036b9b@y18g2000pre.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
> > > desktop-class machine running Linux, gcc, and Sun's Java. One of
> > > my colleagues has done a couple of C++-versus-Java performance
> > > comparisons using real code, and while the C++ versions are
> > > invariably faster, the slowdown for the Java versions is usually
> > > on the order of 10 to 25 percent (e.g., if the C++ version takes 1
> > > minute, the Java version takes 1.1 to 1.25 minutes). There was one
> > > exception -- a program that makes extensive use of trig functions,
> > > which in Java are apparently (sometimes?) implemented in a way
> > > that emphasizes portability over performance, or something. Now,
> > > that's C++ and not C, but I have the impression from another
> > > recent discussion in this group that C and C++ give comparable
> > > performance.

>
> > > Not saying you're wrong, Malcolm, just wondering why your
> > > experience seems so different from mine. Early implementations
> > > of Java were indeed quite slow, but my understanding is that most
> > > current implementations do just-in-time compilation to native code,
> > > and the results are pretty good.

>
> > 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

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));
}
}

  Réponse avec citation
Vieux 13/04/2008, 05h23   #9
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How much fast is C++ than Java?

blmblm@myrealbox.com wrote:

> In article <ftqv65$n5o$1@registered.motzarella.org>,
> Richard <devr_@gmail.com> wrote:
>> blmblm@myrealbox.com <blmblm@myrealbox.com> writes:
>>
>> > In article <1pKdnUM3IrV-A53VRVnyjgA@bt.com>,
>> > Malcolm McLean <regniztar@btinternet.com> wrote:
>> >>
>> >> "Sanny" <softtanks@hotmail.com> wrote in message
>> >>

news:9cfadb86-c03f-4964-96f3-b13020036b9b@y18g2000pre.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.

  Réponse avec citation
Vieux 13/04/2008, 08h36   #10
Robert S
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How much fast is C++ than Java?

On Apr 13, 5:23 am, santosh <santosh....@gmail.com> wrote:
> blm...@myrealbox.com wrote:
> > In article <ftqv65$n5...@registered.motzarella.org>,
> > Richard <de...@gmail.com> wrote:
> >> blm...@myrealbox.com <blm...@myrealbox.com> writes:

>
> >> > In article <1pKdnUM3IrV-A53VRVny...@bt.com>,
> >> > Malcolm McLean <regniz...@btinternet.com> wrote:

>
> >> >> "Sanny" <softta...@hotmail.com> wrote in message

>
> news:9cfadb86-c03f-4964-96f3-b13020036b9b@y18g2000pre.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).
  Réponse avec citation
Vieux 17/04/2008, 16h13   #11
blmblm@myrealbox.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How much fast is C++ than Java?

In article <fts1sh$5ee$1@registered.motzarella.org>,
santosh <santosh.k83@gmail.com> wrote:
> blmblm@myrealbox.com wrote:
>
> > In article <ftqv65$n5o$1@registered.motzarella.org>,
> > Richard <devr_@gmail.com> wrote:


[ 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.
  Réponse avec citation
Vieux 17/04/2008, 16h25   #12
blmblm@myrealbox.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How much fast is C++ than Java?

In article <f5806102-8fc6-4871-98eb-251675570c81@u12g2000prd.googlegroups.com>,
Robert S <roberts218e@gmail.com> wrote:
> On Apr 12, 9:01 pm, blm...@myrealbox.com <blm...@myrealbox.com> wrote:
> > In article <aMidnZ9wgNOpkZzVnZ2dneKdnZydn...@bt.com>,
> >
> >
> >
> > Malcolm McLean <regniz...@btinternet.com> wrote:


[ 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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h16.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,52110 seconds with 20 queries