How much fast is C++ than Java?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sanny

    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
  • Malcolm McLean

    #2
    Re: How much fast is C++ than Java?


    "Sanny" <softtanks@hotm ail.comwrote in message
    news:9cfadb86-c03f-4964-96f3-b13020036b9b@y1 8g2000pre.googl egroups.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.


    Comment

    • Richard

      #3
      Re: How much fast is C++ than Java?

      blmblm@myrealbo x.com <blmblm@myrealb ox.comwrites:
      In article <1pKdnUM3IrV-A53VRVnyjgA@bt. com>,
      Malcolm McLean <regniztar@btin ternet.comwrote :
      >>
      >"Sanny" <softtanks@hotm ail.comwrote in message
      >news:9cfadb8 6-c03f-4964-96f3-b13020036b9b@y1 8g2000pre.googl egroups.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.

      Comment

      • blmblm@myrealbox.com

        #4
        Re: How much fast is C++ than Java?

        In article <ftqv65$n5o$1@r egistered.motza rella.org>,
        Richard <devr_@gmail.co mwrote:
        blmblm@myrealbo x.com <blmblm@myrealb ox.comwrites:
        >
        In article <1pKdnUM3IrV-A53VRVnyjgA@bt. com>,
        Malcolm McLean <regniztar@btin ternet.comwrote :
        >
        "Sanny" <softtanks@hotm ail.comwrote in message
        news:9cfadb86-c03f-4964-96f3-b13020036b9b@y1 8g2000pre.googl egroups.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.

        Comment

        • santosh

          #5
          Re: How much fast is C++ than Java?

          blmblm@myrealbo x.com wrote:
          In article <ftqv65$n5o$1@r egistered.motza rella.org>,
          Richard <devr_@gmail.co mwrote:
          >blmblm@myrealbo x.com <blmblm@myrealb ox.comwrites:
          >>
          In article <1pKdnUM3IrV-A53VRVnyjgA@bt. com>,
          Malcolm McLean <regniztar@btin ternet.comwrote :
          >>
          >"Sanny" <softtanks@hotm ail.comwrote in message
          >>
          news:9cfadb86-c03f-4964-96f3-b13020036b9b@y1 8g2000pre.googl egroups.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.

          Comment

          • Robert S

            #6
            Re: How much fast is C++ than Java?

            On Apr 13, 5:23 am, santosh <santosh....@gm ail.comwrote:
            blm...@myrealbo x.com wrote:
            In article <ftqv65$n5...@r egistered.motza rella.org>,
            Richard <de...@gmail.co mwrote:
            blm...@myrealbo x.com <blm...@myrealb ox.comwrites:
            >
            In article <1pKdnUM3IrV-A53VRVny...@bt. com>,
            Malcolm McLean <regniz...@btin ternet.comwrote :
            >
            "Sanny" <softta...@hotm ail.comwrote in message
            >
            news:9cfadb86-c03f-4964-96f3-b13020036b9b@y1 8g2000pre.googl egroups.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).

            Comment

            • blmblm@myrealbox.com

              #7
              Re: How much fast is C++ than Java?

              In article <fts1sh$5ee$1@r egistered.motza rella.org>,
              santosh <santosh.k83@gm ail.comwrote:
              blmblm@myrealbo x.com wrote:
              >
              In article <ftqv65$n5o$1@r egistered.motza rella.org>,
              Richard <devr_@gmail.co mwrote:
              [ 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.

              Comment

              • blmblm@myrealbox.com

                #8
                Re: How much fast is C++ than Java?

                In article <f5806102-8fc6-4871-98eb-251675570c81@u1 2g2000prd.googl egroups.com>,
                Robert S <roberts218e@gm ail.comwrote:
                On Apr 12, 9:01 pm, blm...@myrealbo x.com <blm...@myrealb ox.comwrote:
                In article <aMidnZ9wgNOpkZ zVnZ2dneKdnZydn ...@bt.com>,



                Malcolm McLean <regniz...@btin ternet.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 multidimensiona l
                array access isn't as fast, given that conceptually a Java
                multidimensiona l 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.currentT imeMillis();
                >
                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.currentT imeMillis();
                >
                System.out.prin tln("Execution time, ms: " + (m2 - m1));
                }
                }
                >

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

                Comment

                Working...