Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Java Faster Than C++?

Posted by michael on Tue Jun 15, 2004 04:25 PM
from the sacred-cow dept.
jg21 writes "The Java platform has a stigma of being a poor performer, but these new performance benchmark tests suggest otherwise. CS major Keith Lea took time out from his studies at student at Rensselaer Polytechnic Institute in upstate New York's Tech Valley to take the benchmark code for C++ and Java from Doug Bagley's now outdated (Fall 2001) "Great Computer Language Shootout" and run the tests himself. His conclusions include 'no one should ever run the client JVM when given the choice,' and 'Java is significantly faster than optimized C++ in many cases.' Very enterprising performance benchmarking work. Lea is planning next on updating the benchmarks with VC++ compiler on Windows, with JDK 1.5 beta, and might also test with Intel C++ Compiler. This is all great - the more people who know about present-day Java performance, the better.""
This discussion has been archived. No new comments can be posted.
Java Faster Than C++? | Log In/Create an Account | Top | 1270 comments (Spill at 50!) | Index Only | Search Discussion
Display Options Threshold:
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
(1) | 2
  • If you want, you can read the actual author's piece instead of a news story about it:

    The Java is Faster than C++ and C++ Sucks Unbiased Benchmark [kano.net]

    • Re:Um, it's online by PhrostyMcByte (Score:2) Tuesday June 15 2004, @05:37PM
      • Re:Um, it's online by dnoyeb (Score:3) Tuesday June 15 2004, @06:25PM
      • Re:Um, it's online (Score:4, Informative)

        by Pointer80 (38430) on Tuesday June 15 2004, @07:54PM (#9437144)
        Read the article. He said that he included JVM startup time in the benchmarks.

        /pointer
        [ Parent ]
        • Re:Um, it's online (Score:5, Informative)

          by GooberToo (74388) on Tuesday June 15 2004, @09:01PM (#9437642)
          The more I read the code, it sure is starting to look more and more like an apples and oranges comparison; which is usually what happens when people do java benchmarks.

          As typically observed, I'm seeing the benchmarks take serious advantage of java's GC mechanism, whereby, they never pay the piper. With C++, the piper is constantly being paid. All of the benchmarks which allocate objects and then delete them, are therefore, invalid. To be fair, I think, you either need to add a System.gc() line in the java code where C++ is doing its deletes or you need to implement your own new and delete operators to function more in line with what java is doing. Until you do either one of those things, the comparisons where objects are being allocated and deallocated are invalid. And frankly, I'm still not sure adding System.gc() is even fair, on either side. The reason is, calling System.gc() simply hints that it's a good idea to collect. There is nothing which requires the collection to take place. So, technically, the call could still be many times faster. On the other hand, I don't know enough about how they handle their gc-hint logic nor am I aware of exactly how much overhead is involved in the actual collection process. If it occurs too often, the shift in workload may be too unfair. Nonetheless, it's a point of very serious contention.

          Just for kicks, I modified objinst.java with, "if( i%(n/1000) == 0 ) System.gc() ;", on the lines that the C++ code had it's delete. When I timed it, it was over twice as slow as the C++ code (24+s vs 55+s). Worse, when I ran it with a 1:1 ratio of delete:System.gc(), I simply got tired of waiting, having waited over 5 minutes.

          So, basically, I'm not nearly as impressed as I first was. Simplistically, it's starting to look like a serious apples and oranges comparison. Elsewhere, you can find other examples of just plain bad code. Where again, with correct C++ code, came in about twice as fast at the Java code, whereby, more optimizations were still possible with the C++ code.

          So, it looks like we're seeing a combination of things here. Looks like a combination of bad code, ideal corner cases for java's hot spot, and invalid comparisons with memory allocation.

          Sadly, I'm once again seriously disappointed in java.
          [ Parent ]
          • Re:Um, it's online by jallen02 (Score:1) Tuesday June 15 2004, @09:11PM
          • Re:Um, it's online (Score:5, Informative)

            by Alan Shutko (5101) on Tuesday June 15 2004, @09:15PM (#9437748)
            (http://web.springies.com/~ats/)
            As typically observed, I'm seeing the benchmarks take serious advantage of java's GC mechanism, whereby, they never pay the piper. With C++, the piper is constantly being paid.

            That's not a bug in the tests, it's a feature.

            The theory behind garbage collection isn't just that it allows the programmer to avoid the effort of watching when to delete things. It's that garbage collection can actually improve performance on certain workloads.

            Forcing a garbage collection for every delete is completely unfair, since it does a full scan of memory, as opposed to just twiddling bits to free a single data value.

            There's no memory leak for these benchmarks... both C++ and Java free all memory used when the process exits. Perhaps you'd prefer a longer-running test with lot of garbage generation (forcing gc to run at some point).
            [ Parent ]
            • Re:Um, it's online by GooberToo (Score:3) Tuesday June 15 2004, @09:34PM
              • Re:Um, it's online by maxwell demon (Score:2) Tuesday June 15 2004, @10:46PM
              • Re:Um, it's online (Score:5, Interesting)

                by ipfwadm (12995) on Tuesday June 15 2004, @11:48PM (#9438771)
                (http://www.adirondack-park.net/)
                I've read many times that it actually does ONLY result in a hint to collect. Unless you can prove otherwise, I'm apt to lean in that direction. Which, actually means that the 1:1 implementation is a more realisitic apples to apples comparison. Can I prove that? No. I'm still hoping a java guru will come in with some insightful tidbits. ;)

                Write a java app that does nothing but repeatedly call System.gc(). Run it with the -verbose:gc option, and watch the garbage collector go. Mind you, this is not 100% proof, but the fact that it prints out [Full GC] over and over again makes me lean pretty strongly in the direction of "the garbage collector actually runs in response to a System.gc(), it's not just a hint".

                One thing I would like Java to do is to allow me to delete objects manually. There are times when the garbage collector really sucks, but 95% of the time it's sufficient, in my experience. And yes, this experience comes from real-world apps.

                Regarding the original topic, I would bet that there are cases where Java really could give C++ a run for its money. However, one liability that Java has compared to C at least is that making everything an object adds a whole lot of object overhead. I had to write a file search routine as part of a Java app, and originally wrote it strictly in Java. The sheer number of File objects that get created by such a routine is ridiculous, and there's really no way to reduce the overhead by reusing the objects -- File objects are immutable. Calling out to JNI resulted in a 3 to 5x performance boost. Does this one example prove anything? No, but it's a heck of a lot more real-world than simply appending a string to itself a few dozen times...
                [ Parent ]
              • Real world applications by Gorimek (Score:2) Wednesday June 16 2004, @01:21AM
              • Re:Um, it's online by angel'o'sphere (Score:2) Wednesday June 16 2004, @09:27AM
              • Re:Um, it's online by Trinition (Score:2) Wednesday June 16 2004, @05:48PM
            • Re:Um, it's online by Trepalium (Score:3) Tuesday June 15 2004, @10:04PM
            • Re:Um, it's online by Xugumad (Score:2) Wednesday June 16 2004, @05:04AM
          • Are you daft? by Julian Morrison (Score:2) Wednesday June 16 2004, @01:49AM
          • Re:Um, it's online by Sinterklaas (Score:2) Wednesday June 16 2004, @03:22AM
          • Re:Um, it's online by sploxx (Score:3) Wednesday June 16 2004, @03:29AM
          • Re:Um, it's online by nikster (Score:3) Wednesday June 16 2004, @04:12AM
          • Re:Um, it's online by Anonymous Coward (Score:1) Wednesday June 16 2004, @06:10AM
          • Re:Um, it's online by Gverig (Score:1) Wednesday June 16 2004, @10:22AM
          • You're disappointed for the wrong reasons by thekm (Score:1) Wednesday June 16 2004, @11:03PM
          • Re:Um, it's online by GooberToo (Score:2) Wednesday June 16 2004, @01:29PM
          • 4 replies beneath your current threshold.
        • 1 reply beneath your current threshold.
      • 1 reply beneath your current threshold.
    • Re:Um, it's online by GooberToo (Score:2) Tuesday June 15 2004, @06:40PM
    • Re:Um, it's online by Kouzdra (Score:1) Wednesday June 16 2004, @02:23AM
    • Matrices by sht_london (Score:1) Wednesday June 16 2004, @03:02AM
      • Re:Matrices by Doc Ruby (Score:2) Wednesday June 16 2004, @09:31AM
        • Re:Matrices by sht_london (Score:1) Wednesday June 16 2004, @10:28AM
          • Re:Matrices by jeremyp (Score:2) Wednesday June 16 2004, @10:35AM
            • Re:Matrices by sht_london (Score:1) Wednesday June 16 2004, @10:52AM
    • Re:Um, it's online by Alexis de Torquemada (Score:1) Wednesday June 16 2004, @03:44AM
    • Re:Java faster than optimised C++ (Um, it's online by Ebola_Influenza (Score:1) Wednesday June 16 2004, @11:24AM
    • Re:Um, it's online (Score:5, Insightful)

      by jdhutchins (559010) on Tuesday June 15 2004, @04:52PM (#9435374)
      (http://jdhutchin.ath.cx/)
      Just becuase you can't write a kernel in it doesn't mean the language is worthless. There are many things that you can do very easily in Java that would be more difficult in other languages, and Java makes it impossible to write many security bugs that plague other languages. You can't do EVERYTHING in Java, but you can do quite a bit.
      [ Parent ]
    • Re:Um, it's online (Score:4, Informative)

      by Too Much Noise (755847) on Tuesday June 15 2004, @05:01PM (#9435492)
      (Last Journal: Tuesday May 18 2004, @11:49PM)
      erm ... I only checked the fibonacci routine, but it's actually quite funny - he's branching recursive calls, a clear case when a smart-enough runtime optimization would work better. I mean, any reasonably smart optimizer would eventually figure out that there are too many calls to the same function with the same argument to just stand by and watch. I'd say that given this difference c++ did quite alright in that one.

      So yes, there are cases when runtime optimizations that are unavailable at compile time can speed things a lot. Does this make Java faster? yes, if you look at the right corner case. Hell NO, if you look at the wrong one.

      The right tool for the job, as usual. And the right tool wielder, otherwise any tool will suck.
      [ Parent ]
      • Re:Um, it's online by Bingo Foo (Score:2) Tuesday June 15 2004, @05:35PM
      • Command and source/test review. (Score:5, Informative)

        by Ninja Programmer (145252) on Tuesday June 15 2004, @06:49PM (#9436651)
        (http://www.pobox.com/~qed/)
        erm ... I only checked the fibonacci routine, but it's actually quite funny - he's branching recursive calls, a clear case when a smart-enough runtime optimization would work better. I mean, any reasonably smart optimizer would eventually figure out that there are too many calls to the same function with the same argument to just stand by and watch. I'd say that given this difference c++ did quite alright in that one.

        This is known as the "halting problem". No, the compiler cannot guarantee the ability to transform a recursive solution to a non-recursive one. The case of the fibonacci algorithm is a particularly difficult one to transform properly if the compiler hasn't special cased it.

        That said -- Ack and Fib are call overhead limited. They examples of poor quality code whose performance is not inner loop based.

        Hash will be C-string (specifically strcmp and sprintf) limited in performance. The performance is therefore very data dependent (since Java uses length delimited strings.) Using a fast string class such as "The Better String Library" (http://bstring.sf.net) would have yielded C++ far better performance. A similar comment applies to the strcat test.

        The Heapsort is a particularly bad implementation. In good implementations, the Intel compiler really takes gcc to town. See: http://www.azillionmonkeys.com/qed/sort.html

        Integer Matrix multiplying is an extremely rare application. So I wouldn't put too much stock in the results here -- though, I would be surprised if there was much differentiation between either Java of C++ on this test.

        The method calling, I think, will be very much limited by the compiler's ability to inline past method calls. I think Intel C/C++ differentiates itself on such things.

        The Nestedloop and random tests are interesting -- I don't see how Java is supposed to beat C++ on it, but its possible to be equal.

        I don't know enough about the Java object system and barely enough about C++ object system to comment on sieve or objinst.

        It seems to me that sumcol and wc are going to be IO limited.

        I don't think this test is exactly fair, as the code is not representative for tasks where performance really matters.
        [ Parent ]
      • Re:Um, it's online by Doctor Faustus (Score:2) Tuesday June 15 2004, @09:17PM
      • 2 replies beneath your current threshold.
    • Re:Um, it's online (Score:4, Informative)

      by mukund (163654) on Tuesday June 15 2004, @05:03PM (#9435523)
      (http://www.mukund.org/)
      Your wish just came true. Check out the JNode [sourceforge.net] project.
      [ Parent ]
    • Re:Um, it's online by poot_rootbeer (Score:3) Tuesday June 15 2004, @05:06PM
    • Re:Um, it's online (Score:4, Informative)

      by cheesybagel (670288) on Tuesday June 15 2004, @05:19PM (#9435708)
      I just looked at hash (C++ [kano.net], Java [kano.net]), but it seems he uses C++ STL and the Java API. This may end up being more of an API than a language test...

      It also does stupid things. Like this:

      int c = 0;
      for (int i=n; i>0; i--) {
      sprintf(buf, "%d", i);
      if (X[strdup(buf)]) c++;
      }
      When this would have worked just fine:
      int c = 0;
      for (int i=n; i>0; i--) {
      if (X[atoi(i)]) c++;
      }

      The alternative is actually shorter, besides being faster and using less RAM.

      I think the person which wrote this didn't know how to program in C++ very well. The two pieces of code are not even equivalent. The second loop is traversed backwards in the C++ version while it is not in the Java version. Don't ask me why.

      [ Parent ]
      • Re:Um, it's online (Score:5, Informative)

        by Anonymous Coward on Tuesday June 15 2004, @05:30PM (#9435842)
        It also does stupid things. Like this:

        int c = 0;
        for (int i=n; i>0; i--) {
        sprintf(buf, "%d", i);
        if (X[strdup(buf)]) c++;
        }

        When this would have worked just fine:

        int c = 0;
        for (int i=n; i>0; i--) {
        if (X[atoi(i)]) c++;
        }


        The code is dumb, yes, but you are wrong, nonetheless. That code won't even compile. I think you meant itoa(), which would be about the same as sprintf in terms of functionality.

        That for() loop is not equivalent to the Java code's for loop, either. In the java code, he used

        if (ht.containsKey(Integer.toString(i, 10))) c++;

        which means that he should have used

        if (X.count(somestringrepofi)) c++;

        X[somestringrepofi] will create an entry for the key if it is not found, making it very different from containsKey().
        [ Parent ]
      • Re:Um, it's online by Tranzig (Score:2) Tuesday June 15 2004, @05:37PM
      • Re:Um, it's online by Anonymous Coward (Score:3) Tuesday June 15 2004, @06:33PM
      • Re:Um, it's online (Score:4, Insightful)

        by ThosLives (686517) on Tuesday June 15 2004, @06:38PM (#9436548)
        (Last Journal: Friday September 21, @07:18AM)
        I agree about the non-equivalent code:

        A fun one:
        Java:

        public static int Ack(int m, int n)
        {
        return (m == 0) ? (n + 1) : ((n == 0) ? Ack(m-1, 1) : Ack(m-1, Ack(m, n - 1)));
        }

        C++:

        int Ack(int M, int N) {
        return(M ? (Ack(M-1,N ? Ack(M,(N-1)) : 1)) : N+1);
        }

        The C++ version could have been written IDENTICALLY (except for the 'public' modifier on the definition) to the Java version, but it was not. I'm not sure what the compiled difference might be, but there is a difference between these two bits of code, notably that in the C++ version there is a tertiary operator evaluated as an argument to a call to Ack, where this is not the case in the Java version. I would guess that this would be a more difficult thing for a compiler to figure out.

        The differences in the methcall sources are even worse; in the C++ version of NthToggle, there are unnecessary dereferences of the this pointer that will kill performance, as well as in the call to new NthToggle(val, 3) in the C++ version is written with the coded constant new NthToggle(true,3) in the java version! It's hardly fair to compare things of this nature.

        The trouble with benchmarking different languages is hard enough due to inherent differences between languages; it's not really enlightening to introduce artificial differences such as these.

        [ Parent ]
      • Re:Um, it's online by dduck (Score:2) Tuesday June 15 2004, @06:44PM
      • Re:Um, it's online by gsasha (Score:1) Wednesday June 16 2004, @01:30AM
      • Re:Um, it's online by cheesybagel (Score:2) Tuesday June 15 2004, @08:58PM
      • 2 replies beneath your current threshold.
    • Re:Um, it's online by TheRealMindChild (Score:2) Tuesday June 15 2004, @06:06PM
    • Re:Um, it's online by Felinoid (Score:1) Tuesday June 15 2004, @07:01PM
    • Re:Um, it's online by sammck (Score:1) Tuesday June 15 2004, @11:39PM
    • Re:Um, it's online by schabi (Score:1) Wednesday June 16 2004, @03:55AM
    • 4 replies beneath your current threshold.
  • The Great Computer Language Shootout (Score:5, Informative)

    by thebra (707939) * on Tuesday June 15 2004, @04:28PM (#9434976)
    (http://www.jasonbradleyonline.com/ | Last Journal: Tuesday April 27 2004, @04:36PM)
    Correct link [bagley.org]
  • Yes but... by Anonymous Coward (Score:2) Tuesday June 15 2004, @04:28PM
  • Fact: C++ is dying....

    Oh hell, I don't have the heart. Nevermind.
  • Anyone got a match? (Score:5, Funny)

    by nebaz (453974) on Tuesday June 15 2004, @04:29PM (#9435003)
    Here's some kindling...

    vi is better than emacs
    bsd is better than linux
    gnome is better than kde
    .
    .
    .
    anything else?

    oh yeah...
    my dad can beat up your dad.
    And you smell funny.
  • Ah...yes... by Anonymous Coward (Score:1) Tuesday June 15 2004, @04:29PM
  • meh by jnapalm (Score:2) Tuesday June 15 2004, @04:30PM
    • Re:meh by mobby_6kl (Score:1) Tuesday June 15 2004, @06:11PM
    • 1 reply beneath your current threshold.
  • Just one game by sien (Score:2) Tuesday June 15 2004, @04:30PM
    • Re:What are -client and -server? by gtrubetskoy (Score:2) Tuesday June 15 2004, @04:52PM
    • different requirements (Score:5, Informative)

      by vlad_petric (94134) on Tuesday June 15 2004, @04:57PM (#9435450)
      (http://slashdot.org/)
      The server one is optimized for throughput and concurrency, whereas the client one for latency.

      You might think that the two are the same, but the two settings actually make a visible impact if you're running on a multi-processor system. Most notably, the garbage collector and locking primitives are implemented differently.

      [ Parent ]
    • Re:What are -client and -server? (Score:5, Informative)

      by Jennifer E. Elaan (463827) on Tuesday June 15 2004, @05:29PM (#9435832)
      (http://caladan.nanosoft.ca/)
      "Some of the other differences include the compilation policy used, heap defaults, and inlining policy."

      Am I the only one who noticed the "inlining policy" thing? Considering "method call" was one of the most compelling arguments for his case (by orders of magnitude!), the fact that the methods being "called" are being called *INLINE* should mean something.

      If you're allowed to turn on the java inliner, surely you can spare the time to turn on the C++ one as well (he used -O2, not -O3, for compiling the C++ apps).

      [ Parent ]
    • Re:What are -client and -server? by roofingfelt (Score:1) Wednesday June 16 2004, @12:50PM
    • 1 reply beneath your current threshold.
  • by exp(pi*sqrt(163)) (613870) on Tuesday June 15 2004, @04:30PM (#9435031)
    (Last Journal: Monday January 06 2003, @10:36PM)
    ...on x86? Please! Wake me up when someone who knows enough about C++ to pick a decent x86 compiler runs some benchmarks.
  • Of course it's faster -- by ianbnet (Score:1) Tuesday June 15 2004, @04:30PM
  • Cross platform by leakingmemory (Score:2) Tuesday June 15 2004, @04:31PM
  • Benchmarks by AnomalyConcept (Score:1) Tuesday June 15 2004, @04:32PM
    • Re:Benchmarks by thebra (Score:2) Tuesday June 15 2004, @04:37PM
    • Re:Benchmarks by Hoodsen (Score:3) Tuesday June 15 2004, @04:52PM
    • 1 reply beneath your current threshold.
  • Languages vs Compilers (Score:5, Insightful)

    by Anonymous Coward on Tuesday June 15 2004, @04:32PM (#9435070)

    Java and C++ are language. Languages aren't "faster" or "slower", but compilers for them might be. I find it somewhat underhanded to put the languages in the header when it's really comparing compilers.

    Not to mention, inter-language compiler benchmark[et]ing is notoriously difficult to get 'right'. The programs tested are often stupid (doesn't do anything meaningful), or constructed by a person with more skill/bias for one language than the other.

  • -O3 by Anonymous Coward (Score:1) Tuesday June 15 2004, @04:33PM
    • Re:-O3 by Anonymous Coward (Score:1) Tuesday June 15 2004, @04:34PM
    • Re:-O3 by Svennig (Score:1) Tuesday June 15 2004, @05:16PM
    • 1 reply beneath your current threshold.
  • Nice to hear... (Score:4, Insightful)

    by twocoasttb (601290) on Tuesday June 15 2004, @04:33PM (#9435088)
    It's been ages since I've programmed in C++, but it's good to know see these favorable comparisons. I think about the Struts/Hibernate/Oracle applications I write today and shudder when I imagine what how difficult it would be to have to develop web applications in C++. C++ will be around forever and certainly has its place, but long live Java.
  • A few points... (Score:5, Insightful)

    by mindstrm (20013) on Tuesday June 15 2004, @04:34PM (#9435107)
    There seem to be some unanswered questions here..

    - How equivalent were the benchmarks? Where they programmed in an optimum way for their respective compilers and libraries? I'm sure the java ones were.. what about the C++ ones? The author states he doesn't understand G++ very well.

    G++ is also known to not produce the best results.

    "I rant it with -O2"

    My guess is many of the tests were not implemented properly in c++.

    The main clue would be this... I can understand java having better than expected performance.. but there is no way I can accept that java is that much FASTER than properly done C++... it doesn't make any sense.

    • Re:A few points... by leakingmemory (Score:1) Tuesday June 15 2004, @04:40PM
    • Re:A few points... by unoengborg (Score:2) Tuesday June 15 2004, @05:01PM
    • Re:A few points... by kaffiene (Score:1) Tuesday June 15 2004, @05:01PM
    • Re:A few points... by nairbv (Score:1) Tuesday June 15 2004, @05:07PM
    • Re:A few points... (Score:5, Insightful)

      by Trillan (597339) on Tuesday June 15 2004, @05:14PM (#9435644)
      (http://pyile.com/ | Last Journal: Tuesday December 19 2006, @01:33PM)

      Maybe it does make sense. But what it proves is that C++ (at least as implemented by GCC, but it's probably a design flaw) is slower than expected, not that Java is blazingly fast.

      [ Parent ]
    • The main flaw of such benchmarks... by WARM3CH (Score:3) Tuesday June 15 2004, @05:25PM
    • Re:A few points... (Score:5, Interesting)

      by Cthefuture (665326) on Tuesday June 15 2004, @05:33PM (#9435879)
      I've been playing with those benchmarks for ages. I use them any time a new language comes out or if I just want to do some independent testing.

      A couple points:

      - The "Great Shootout" benchmark times are sometimes way off because the run-time was too short to get an accurate reading. In those cases the tests should have been run with higher values to really stress the machine. That doesn't appear to be an issue in this test though (assuming his graph values are in seconds).

      - Many of the C++ tests are not optimized. That is, they use C++ features like the iostream stuff (cout, and friends) which is extremely slow. The C versions are available and very fast. C++ is pretty much just an extension of C. You don't need to use C++ features if they slow you down. Another one is the hash stuff. In the C++ hash benchmark there are some goofy mistakes made by using the brackets [] operator where it forces several unnecessary lookups. You can also substitute a better STL hashing function that is faster (like MLton's insanely fast hasher).

      - The test could be done by comparing C to Java. Anything in C++ can be made as fast as an equivalent C version but there are not many programmers that know how. Just assume anything in C++ will run as fast as a C version, and if it doesn't then you did something wrong. The hash tests would be easier in C++ though. If they were written properly they would kill the Java version.

      With that said, I'm going to try these tests myself because I do not believe the results to be accurate. but who knows...
      [ Parent ]
    • Re:A few points... by GooberToo (Score:3) Tuesday June 15 2004, @07:27PM
    • clues that this is one big troll by twitter (Score:2) Wednesday June 16 2004, @12:05AM
      • yeah, right by twitter (Score:2) Wednesday June 16 2004, @08:57AM
        • ha ha. by twitter (Score:2) Thursday June 17 2004, @10:09PM
          • 1 reply beneath your current threshold.
        • 3 replies beneath your current threshold.
      • 2 replies beneath your current threshold.
    • Re:A few points... by j3110 (Score:2) Wednesday June 16 2004, @09:47AM
    • 3 replies beneath your current threshold.
  • Could use a good analysis (Score:5, Interesting)

    by GillBates0 (664202) on Tuesday June 15 2004, @04:34PM (#9435113)
    (http://slashdot.org/~GillBates0 | Last Journal: Tuesday July 10, @04:36PM)
    The results are very non-intuitive. An extra layer between the program -> CPU implies an extra amount of overhead - be it any layer (VM at the Application layer, VM at the OS layer, or even at the CPU layer (hyperthreading)).

    I looked at his results page quite extensively, but failed to find a good analysis/justification of the results. Just saying that the Server JVM is better than the Client JVM is *not* enough.

    I want to know where the C++ overhead comes from, which Java manages to avoid - does the JVM do better optimization because it is given a better intermediate code (bytecode)? Is it better at doing back/front end optimizations (unlikely given gcc's maturity).

    I tried to look for possible discrepancies in the results, but the analysis will definitely take more time - and I think it's the job of the experimenter to do a proper analysis of the results. Liked his choice of benchmarks though.

    • Re:Could use a good analysis by Anonymous Coward (Score:1) Tuesday June 15 2004, @04:42PM
      • Now you're talking Profiling (Score:5, Interesting)

        by GillBates0 (664202) on Tuesday June 15 2004, @04:48PM (#9435323)
        (http://slashdot.org/~GillBates0 | Last Journal: Tuesday July 10, @04:36PM)
        and that's a topic that gets me all worked up (my Master's Thesis touch on Program Profiling).

        So, if the JIT computes Hot/Cold Paths, and optimizes the Hot paths, then it should work better and better on successive runs (as more and more profiling information is gathered). On the other hand, there will be cases where it performs worse, as profiles are gathered for specific inputs.

        That means that if an average of say 5 runs (on the same input) is taken, it will have an unfair advantage (since gcc did NOT have the advantage of profiling information (see man gprof or similar)). Using Profiling as an optimization tool is *always* unfair unless both tools are provided with the advantage of the same profiling information. This is a valid question for the author then: if the JIT/javac/JVM uses profiling information, gcc should too, for fair comparison.

        PS: I have seen this argument being made by my Professor and audiences at compiler conferences.

        [ Parent ]
    • Re:Could use a good analysis by Magnus Pym (Score:3) Tuesday June 15 2004, @04:48PM
    • Re:Could use a good analysis by gwernol (Score:2) Tuesday June 15 2004, @04:58PM
    • Re:Could use a good analysis (Score:5, Interesting)

      by jfengel (409917) on Tuesday June 15 2004, @05:07PM (#9435559)
      (http://slashdot.org/ | Last Journal: Monday November 03 2003, @03:59PM)
      His examples are all non-GUI things; they're pure CPU benchmarks. That's one major case where Java is certainly slower than C++.

      Most of his tests are big loops (primes, string concatenation, etc.) These are cases where (as a sibling poster mentioned) hot path analysis can do you a world of good. A heavily tuned C++ program can do it just as well, or better, but the point of using a high-level language is that you don't have to do those optimizations yourself; you write the code in whatever way seems natural and you let the compiler optimize.

      In a long-running Java program, you don't have that extra layer between the program and the CPU. The JIT does a real native compilation and passes control off to it. Once that's started, it runs just as fast as any other assembly code. Potentially faster, given that the JIT can look at the current run and optimize based on the way the code is going: the precise CPU it's running on, where things are in memory, how far it can afford to unroll a loop, what loop invariants it can lift, etc. It can even replace code as it runs.

      The question then is, does the one-time (albeit run-time) optimization do more good than it costs?

      That's especially easy on a hyperthreaded system. In a C++ program, these loops will run in a single thread on a single CPU, so if the JIT compiler runs on the other (virtual) CPU, you get its effort for free. Even the garbage collector can run on the other CPU, so you get the convenience of memory management with no total performance cost. (You do burn more CPU cycles, but you use up no extra wall-clock time.)

      GCC is very mature, but it doesn't have the option of changing the code at run time. Especially on modern CPUs with their incredibly deep pipelines, arranging your code to avoid pipeline stalls will depend a lot on runtime considerations.

      Also, Java has a few advantages over C++ in optimization. It's very easy to analyze Java programs to be certain that certain memory locations absolutely will not be modified. That's much harder in languages with native pointers. Those invariants allow you to compile out certain calculations that would have to be done at runtime in a C/C++ program. You can even start spreading loop cycles over multiple CPUs, but I'm pretty certain that the present JVMs aren't that smart.

      These results are toy benchmarks, and not really indicative of real performance, even on purely non-GUI code. But I wanted to outline the reasons why the results aren't just silly, and they do have a theoretical basis.
      [ Parent ]
    • Re:Could use a good analysis by brunes69 (Score:2) Tuesday June 15 2004, @05:11PM
    • Re:Could use a good analysis by grotgrot (Score:2) Tuesday June 15 2004, @08:59PM
    • 1 reply beneath your current threshold.
  • the more people... by bsDaemon (Score:1) Tuesday June 15 2004, @04:36PM
  • Riiiiiiight by SmallFurryCreature (Score:1) Tuesday June 15 2004, @04:36PM
  • Expert results (Score:5, Insightful)

    by otterpop81 (784896) on Tuesday June 15 2004, @04:36PM (#9435145)
    Some of the C++ tests would not compile. I've never been very good at decoding GCC's error messages, so if I couldn't fix a test with a trivial modification, I didn't include it in my benchmarks.

    That's Great! I can't figure out GCC's error messages, but I offer definitive proof that Java is faster than C++. Nice.

  • I care that Java is an inconvenient pain to develop in and use. I care that I have to start a mini-OS just to run a Java program. I care that the language is under the control of one vendor. I care that the 'intialization == resource allocation' model doesn't work in Java. I care that the type system is too anemic to support some of the more powerful generic programming constructs. I care that I don't get a choice about garbage collection. I care that I don't get to fiddle bits in particular memory locations, even if I want to.

    I think Java is highly overrated. I would prefer that a better C++ (a C-like memory model, powerful generic programming, inheritance, and polymorphism) that lacked C++'s current nightmare of strangely interacting features and syntax.

    I use Python when I don't need C++s speed or low-level memory model, and I'm happier for it. It's more flexible than Java, much quicker to develop in, and faster for running small programs. Java doesn't play well with others, and it was seemingly designed not to.

    Besides, I suspect that someone who knew and like C++ really well could tweak his benchmarks to make C++ come out faster again anyway. That's something I've noticed about several benchmarks that compare languages in various ways.

  • Java vs. C++ by sameerdesai (Score:1) Tuesday June 15 2004, @04:38PM
  • Flawed Test (Score:3, Insightful)

    by Emperor Shaddam IV (199709) on Tuesday June 15 2004, @04:38PM (#9435182)
    Comparing one C++ compiler (gcc) against the Java JVM on one operating system is not much of a test. I love Java, but this is almost something like microsoft would do. Test one specific OS, compiler, and configuration, and then make a blind, far-reaching statement. A fair test would include several platforms and compilers.
  • Some problems I had using Java by Anonymous Coward (Score:2) Tuesday June 15 2004, @04:39PM
  • disable JS to get past his redirect :) by drgroove (Score:2) Tuesday June 15 2004, @04:39PM
  • Maybe on Fantasy Island by boy_afraid (Score:1) Tuesday June 15 2004, @04:40PM
  • Only one? by Matthew Weigel (Score:2) Tuesday June 15 2004, @04:40PM
    • Re:Only one? by Matthew Weigel (Score:2) Tuesday June 15 2004, @04:44PM
    • 1 reply beneath your current threshold.
  • One example of why the tests are BS (Score:5, Insightful)

    by mypalmike (454265) on Tuesday June 15 2004, @04:40PM (#9435200)
    (http://www.mypalmike.com/)
    From methcall.cpp:

    int
    main(int argc, char *argv[]) {
    int n = ((argc == 2) ? atoi(argv[1]) : 1);

    bool val = true;
    >> Toggle *toggle = new Toggle(val);
    for (int i=0; i<n; i++) {
    val = toggle->activate().value();
    }
    cout << ((val) ? "true" : "false") << endl;
    delete toggle;

    val = true;
    NthToggle *ntoggle = new NthToggle(val, 3);
    for (int i=0; i<n; i++) {
    val = ntoggle->activate().value();
    }
    cout << ((val) ? "true" : "false") << endl;
    >> delete ntoggle;

    return 0;
    }

    Why allocate and deallocate an object within the scope of a function? Well, in C++, there's no reason, so this is bad code. You can just declare it as a non-pointer and it lives in stack space. But guess what? You can't do that in Java: all objects are allocated on the heap.

    That, and using cout instead of printf, are probably why this is slower than the "equivalent" Java.

    -_-_-
  • Next step by localman (Score:2) Tuesday June 15 2004, @04:40PM
  • Some performance myths (Score:5, Interesting)

    by vlad_petric (94134) on Tuesday June 15 2004, @04:41PM (#9435227)
    (http://slashdot.org/)
    First of all, g++ actually sucks big time in terms of performance. Intel C Compiler, with inter-procedural optimizations enabled, produces code that's almost always 20->30% faster than g++. I've actually once compiled C code with g++ and it was visibly slower than the same code compiled with gcc ... oh well.

    Now, regarding java performance ... Java isn't slow per se, JVMs and some apis (most notably swing) are. Furthermore, JVMs usually have a slow startup, which gave java a bad name (for desktop apps startup matters a lot, for servers it's hardly a big deal). Java can be interpreted, but it doesn't have to be so (all "modern" JVMs compile to binary code on the fly)

    Bytecode-based environments will, IMNSHO, eventually lead to faster execution than with pre-compilation. The reason is profiling and specialized code generation. With today's processors, profiling can lead sometimes to spectacular improvements - as much as 30% performance improvements on Itanium for instance. Although Itanium is arguably dead, other future architectures will likely rely on profiling as well. If you don't believe me, check the research in processor architecture and compiling.

    The big issue with profiling is that the developper has to do it, and on a dataset that's not necessarily similar to the user's input data. Bytecode environments can do this on-the-fly, and with very accurate data.

  • by Sebastopol (189276) on Tuesday June 15 2004, @04:43PM (#9435242)
    (http://slashdot.org/)

    Why did he use the strdup function when he already has the char array from the previous sprintf?? That step incurs a huge and unnecessary penalty w/an allocation, just pass the pointer!

    Also, in the second 'for' loop in hash2, he does extra work beacuse he already looked up (*k).second.

    shouldv'e done hash2[k->first] = k->second; ...to avoid another lookup penalty.

    Tell me I'm not crazy.

  • Bad Comparison by PalmKiller (Score:1) Tuesday June 15 2004, @04:44PM
  • what the hell? by minamar (Score:1) Tuesday June 15 2004, @04:45PM
  • Ridiculous by ddelrio (Score:1) Tuesday June 15 2004, @04:45PM
    • Re:Ridiculous by Mithrandir (Score:1) Tuesday June 15 2004, @05:00PM
  • What about gcj? (Score:5, Interesting)

    by joshv (13017) on Tuesday June 15 2004, @04:45PM (#9435280)
    I'd be interested in comparing the speed of the native code generated by gjc to the that of JVM.

    -josh
  • java *can* be fast... (Score:5, Interesting)

    by alphafoo (319930) <loren@boxbe.com> on Tuesday June 15 2004, @04:45PM (#9435282)
    (http://kunafa.maktoobblog.com/)
    A year and a half ago I proposed building a standalone server-type application using Java, and my client scoffed at me because "everyone knows Java is slow". It was 1.4.2 on rh8.0 running on standard dual xeons. It ran pretty fast, and then I profiled it. Repeatedly. I replaced some of the stock library routines with my own faster ones or ones I found on sourceforge, found the most monitor-contentious areas and tuned them, played around with different GC strategies for the given hardware, and ended up with something that is amazingly fast. Scaled to 400+ HTTP requests per second and over a thousand busy threads, per node. Some of the speed bumps came for free, like when NPTL threads came available in the 2.4 kernel.

    I am starting on a new standalone server now doing something different, but I am going to stick with Java, and will be happy to see what 1.5 does for me.

    But I have seen Java run slow before, and I will tell you this: in every instance it is due to someone writing some needlessly complicated J2EE application with layer upon bloaty layer of indirection. All the wishing in the world won't make one of those behemoths run fast, but it's not fair to blame Java. Maybe blame Sun for EJB's and their best practices, or blame BEA for selling such a pig.

    Stuff I like in the Java world:

    • sun's 1.4.2 on hyperthreaded xeons
    • Jetty (fast!)
    • Piccolo XML parser (fast!)
    • Lea's concurrency library
    • Grosso's expirable cache [click] [onjava.com]
    • hibernate
    • JAM on Maven [click] [javagen.com]
    • eclipse
  • Slow C++ compiler (Score:4, Informative)

    by siesta at uni (311500) on Tuesday June 15 2004, @04:46PM (#9435301)
    The article says he used GCC to compile the C++ versions, but GCC produces code that isn't nearly as good as the Intel compiler for example. (Here [ddj.com], but no good if you don't subscribe)
    A lot of the test results are close, and I think a different compiler would change the outcome.
  • by IvyMike (178408) on Tuesday June 15 2004, @04:48PM (#9435322)
    Here is my experience with C++ vs. Java: At my company, we had a specialized image viewing program. The original program was written in C++ years ago, and performance sucked even on modern machines. It probably had a dozen man-years of time in it. We decided to re-write it in java.

    We knew java in theory should be worse than C++ at manipulating large blocks of raw data, so we spent some time architecting, prototyping, and profiling java. We quickly learned the limitations and strengths.

    The result? After 4 engineers worked for 6 months, we had a program that was rock solid, had more features, had a modern UI, and was WAY faster. Night and day; the old program felt like a hog, and the new program was zippy as anything. And the new code is fewer lines, and (in our opinion) way more maintainable. Since the original release, we've added severeal new features after day or two of work; the same features never would have happened on the old version, because they would have been too risky.

    So the question is this? Could we have re-written or refactored the C++ program and gotten the same speed benefits? No doubt, such a thing is possible. But we are all convinced there is NO WAY we could have done it with as little effort. The C++ version would have taken longer to write and debug.
  • Java maturity vs. .NET by Tomster (Score:2) Tuesday June 15 2004, @04:48PM
  • c# is FASTER than JAVA by gamesmash (Score:2) Tuesday June 15 2004, @04:48PM
  • Meaningless, but... by groomed (Score:2) Tuesday June 15 2004, @04:49PM
  • more Java perf. tips at javaperformancetuning.com by Kunta Kinte (Score:2) Tuesday June 15 2004, @04:50PM
  • O3? Equivalent programs? (Score:5, Insightful)

    by morcheeba (260908) * on Tuesday June 15 2004, @04:52PM (#9435372)
    (Last Journal: Wednesday August 03 2005, @10:21AM)
    Why did he use only -O2?

    -O3 adds function inlining and register renaming [gnu.org].

    Also, some of the code doesn't look too much of a test of the language, but more of a test of the libraries. Both versions of hash rely on the library implementations, and it looks like hash.cpp [kano.net] does an extra strdup that the java version doesn't. I don't know either of the hash libraries well enough, but I don't see why this significant slowdown would be necessary in the gcc version.
    • 1 reply beneath your current threshold.
  • Troll (Score:5, Insightful)

    by stratjakt (596332) on Tuesday June 15 2004, @04:52PM (#9435390)
    (Last Journal: Sunday November 11, @09:31AM)
    This test proves that Sun's optimized Java compiler and VM are faster on Red Hat than gcc.

    Gcc is designed for compatibility with a wide range of architectures, and is not optimized for a single one. He also (apparantly) used stock glibc from Red Hat. And only one "test", the method call test, showed java to be a real winner. And even then, it's server-side Java, which is meaning less when you talk about it as a day-to-day dev language (ie; creating standalone client-side apps).

    Intel's (heavily optimized) C++ compiler should be a damn sight faster, and so should VC++.

    This "comparison" is so limited in scope and meaning, that this writeup should be considered a troll.

    Hell, read his lead-in:

    "I was sick of hearing people say Java was slow, when I know it's pretty fast, so I took the benchmark code for C++ and Java from the now outdated Great Computer Language Shootout and ran the tests myself."


    Ie; I set out to prove Java is teh awesome and c++ is teh suck!

    If anything it proves something I've known intuitively for a long time. gcc does not produce x86 code that's as fast as it could be. That's a trade-off for it being able to compile for every friggin cpu under the sun.

    I can't wait till RMS takes personal offense and goes on the attack.
    • Re:Troll by wmshub (Score:2) Tuesday June 15 2004, @07:06PM
    • Re:Troll by Ninja Programmer (Score:3) Tuesday June 15 2004, @10:55PM
    • Re:Troll by KZigurs (Score:2) Wednesday June 16 2004, @03:42AM
    • Re:Troll by mattgreen (Score:2) Wednesday June 16 2004, @06:28AM
    • Re:Troll by Tim C (Score:2) Wednesday June 16 2004, @08:04AM
  • by cardshark2001 (444650) on Tuesday June 15 2004, @04:53PM (#9435402)
    It's just not possible. It could be comparable, in limited cases, but not faster. It just can't be. If you find that it is, there's something wrong with your experiment. Does this mean Java is bad? Not necessarily. It depends on your purpose.

    Okay, so how could I make a blanket statement like that? In this case, the author of the paper merely used a compiler switch in gcc (-o2). That doesn't mean his c++ was highly optimized. It just means he told the compiler to do its best. If you really wanted to highly optimize c++, you would study the compiler and how it works, and you would profile the actual assembly that the compiler generates to make sure that it didn't do anything unexpected. Given *any* algorithm, I can come up with a c++ implementation that is faster than a Java implementation. Period.

    The java compiler actually compiles to a virtual opcode format, which is then interpreted by the java virtual machine at runtime. Imagine if you needed to talk to someone on the phone, but instead of talking to them, you had to talk through an intermediary. Is there any possible way that it could be faster than talking to the person directly?

    Now, I'll be the first to point out that a badly implemented c++ algorithm could be much slower than a well implemented Java algorithm, but I'll take the pepsi challenge with well written code any time, and win.

    Relying on benchmarks and code somebody else wrote doesn't prove anything. Did he get down and dirty with the compiler and look at the generated assembly code? No, he did not.

    Move along, there's nothing to see here.

  • OT - Maybe by Stevyn (Score:2) Tuesday June 15 2004, @04:53PM
    • Re:OT - Maybe by dmaxwell (Score:2) Tuesday June 15 2004, @05:22PM
  • To borrow (and mutilate) a phrase from Satchmo by dtrent (Score:2) Tuesday June 15 2004, @04:54PM
  • No dice by finkployd (Score:2) Tuesday June 15 2004, @04:55PM
  • The performance hit is negligible... (Score:3, Interesting)

    by bl8n8r (649187) on Tuesday June 15 2004, @04:55PM (#9435422)
    Depending on the application. I will gladly trade the write-once-run-almost-anywhere advantage for a little heavier application, within reason. (Sun's "soundtool" java app is a sadistic waste of reason) Not having to support multiple platforms, compilers, Licenses, IDEs, utility applications, etc, etc is a big plus too. Java's inbred sluggishness is not cause to ignore the advantages it offeres in other areas. I also like the idea of having some competition in the commercial development arena again.
  • *Can* be faster by miyako (Score:2) Tuesday June 15 2004, @04:57PM
  • My brief tests seem to agree by Rhesus Piece (Score:1) Tuesday June 15 2004, @04:59PM
  • Computer vision by feelyoda (Score:2) Tuesday June 15 2004, @05:00PM
  • The methodology used here sucks (Score:4, Interesting)

    by Troy Baer (1395) on Tuesday June 15 2004, @05:00PM (#9435480)
    (http://home.columbus.rr.com/tbaer/)
    The author doesn't really explain why he didn't compile with -O3 aside from a very slight amount of hand-waving about space-speed tradeoffs, which quite frankly I don't buy. If you're benchmarking, why wouldn't you optimize as heavily as possible? If he was really interested in benchmarking this stuff objectively, he could've at least shown that there wasn't much different between -O2 and -O3. Not to mention the question of whether g++ generates good binary code on a given platform...

    This didn't exactly fill me with optimism either:

    I don't have an automated means of building and benchmarking these things (and the scripts that came with the original shootout didn't run for me). I really do want you to test it on your own machine, but it's going to take some work, I guess.
    This would seem to imply that the author does not know much about either shell scripting or Makefiles. I'm not sure I'm willing to trust benchmarks from somebody who can't figure out an automated way to build and run them.

    --Troy
  • java methcall benchmark not making virtual calls by bgs4 (Score:2) Tuesday June 15 2004, @05:03PM
  • it's reasonable (Score:3, Insightful)

    by trance9 (10504) on Tuesday June 15 2004, @05:03PM (#9435522)
    (http://www.webmacro.org | Last Journal: Wednesday June 25 2003, @11:25PM)
    In response to what many of you have and will write:

    -- there is not necessarily any "extra layer" created by the JVM. the whole idea is that the JVM is actually a run-time compiler, and when it's done compiling the .class to native code you really have native code directly executing.

    -- the JVM runtime compiler can perform optimizations that are not available to a C++ compiler. for example, if the JVM realizes that there is only one instance loaded of an abstract/virtual class it can compile all the code that accesses it statically against that single code, as if there were no inheritence at all, saving a pointer reference. a C++ compiler can never do that because it does not know what you will link against.

    -- Many of you are simply going to find ways to criticize Java because you are religious. You used to criticize performance, and if that is taken away from you, you will say it was never really important and criticize something else. You need to think whether or not you are being objective and rational, or simply theocratic.

    -- Yes you could likely optimize the C++ code better. Some suggested replacing the inefficient cout's with printf's but that is really eliminating the ++ part of the C++ language. If you can't take advantage of C++'s OO features then there isn't any point in comparing the language with Java--without those higher level features you are programming in the 70's. Guess what, assembler is even faster. So it is fair to compare C++'s high level features with Java.

    -- Repeat: Some of you are simply religious.
  • is it... by null-sRc (Score:1) Tuesday June 15 2004, @05:06PM
  • Java -server always breaks micro-benchmarks by giliath (Score:2) Tuesday June 15 2004, @05:07PM
  • Client JVM Choices? by john_smith_45678 (Score:2) Tuesday June 15 2004, @05:09PM
  • Deja vu all over again by Baldrake (Score:1) Tuesday June 15 2004, @05:09PM
  • Retried Benchmark Results by Rhesus Piece (Score:1) Tuesday June 15 2004, @05:11PM
  • methcall results are just wrong! by Funkitup (Score:1) Tuesday June 15 2004, @05:11PM
    • 1 reply beneath your current threshold.
  • Maybe but... by JustinXB (Score:1) Tuesday June 15 2004, @05:12PM
  • The good ol' benchmark pissing contest... by l3ool (Score:1) Tuesday June 15 2004, @05:15PM
  • I smell some BS in the CS by manthraxis (Score:1) Tuesday June 15 2004, @05:15PM
  • Built-in Java? by LS (Score:2) Tuesday June 15 2004, @05:17PM
  • Meaningless Question by Waffle Iron (Score:2) Tuesday June 15 2004, @05:17PM
  • Programmer productivity is a more important metric by StLawrence (Score:1) Tuesday June 15 2004, @05:18PM
  • It's the STL that is slow, not the language by jay2003 (Score:1) Tuesday June 15 2004, @05:24PM
  • shenanigans by Anonymous Coward (Score:1) Tuesday June 15 2004, @05:30PM
  • by adiposity (684943) on Tuesday June 15 2004, @05:31PM (#9435854)
    What concerns me most is the amount of memory it requires. In theory, once the requisite stuff is loaded into memory, Java byte code can be processed at nearly the same rate that C++ code is. Depending on the bytecode and assembly that are generated in each case, Java or C++ could end up being faster. I think it's obvious that Java incurs some overhead in translating the bytecode, which ought to slow it down *some*, but that amount can be minimized.

    On the other hand, Java takes a great deal of memory. If C++ had a dedicated server sitting in memory, ready to execute commands for it, it probably would speed up execution, but that wouldn't mean C++ were faster.

    After accepting the memory hit for Java, the performance on things like apps servers seems to be pretty decent. I have yet to use a java client application, however, where I didn't feel that it was sluggish (even after loading). There are only two explanations: all java code is written poorly, or Java inherently causes a performance hit.

    As we abstract languages more and more, we see performance hits for increased functionality and ease of developing. We also see that, because of the easier development, it is easier to improve scalability and use more efficient algorithms. It is rare that a program cannot be sped up by hand-optimizing the assembly, but it is also rare that anyone has time to design the much more critical optimized algorithms at such a low level. Therefore, I predict that eventually Java (or something like it) will be embraced as programmer time matters more than speed of execution.

    The one thing that disturbs me about Java is that, while in C++, it is easy to change the assembly while maintaining the C/C++ code, in Java, you are tied to platform-independent code, which prevents you from doing platform specific optimizations. You have to depend on the native java implementations and/or widget toolkits for those kind of things. And so far, although the situation is improving, I've been pretty unhappy with the speed and my ability to improve it.

    -Dan
  • Quick analysis... (Score:3, Informative)

    by the_skywise (189793) on Tuesday June 15 2004, @05:44PM (#9436002)
    In the bulk of his results, C++ on an i686 beat out the CLIENT JVM every time except in two tests. Object creation and word count. In the object creation test the code is biased towards Java. He's creating the objects AND DELETING THEM in C++, but Java's garbage collection probably isn't doing the deletion at all.

    The other test is the word count. This one is interesting because he sets the streambuffer to 4k in both Java and C++. But in the C++ version the stream won't preload to fill the buffer. So the amount being cached is UNKNOWN. I can't speak for the Java version but I bet it preloads the entire file.

    That leaves the Server JVM switch. In which case I think you're seeing alot more code inlining then the standard C++ compiler generates.

    Either way, this is hardly a definitive test.
  • Makes Sense by Queer Boy (Score:2) Tuesday June 15 2004, @05:46PM
  • Is it faster? by areve (Score:1) Tuesday June 15 2004, @05:48PM
  • Explanation (Score:5, Interesting)

    by gillbates (106458) on Tuesday June 15 2004, @05:51PM (#9436075)
    (http://www.angelfire.com/il/macroman | Last Journal: Friday March 30 2007, @07:17PM)

    Reviewing the console log, we find that when java programs were tested with a large number of iterations, Java only performed better on one test.

    • We don't know which OS was used. While each C++ program must have been loaded entirely each time, the JVM may very well have remained cached in RAM between tests - hence a faster startup time, which explains:
    • Java is actually slower than C++, but because the JVM was already cached in RAM, it ran faster on those tests which involved a relatively small number of iterations. However, when the number of iterations was increased, Java was always slower than C++, with the exception method call and object instantiation:
    • Object instantiation isn't really relevant because of the fact that C++ programs call the OS for every single memory request, where as Java can pool it. This test measured the speed of the kernel's malloc more than the speed of C++.
    • In most of the C++ code, IO is placed in the inside loops, meaning that the program is really testing the throughput of libc and the OS, as opposed to the efficiency of the generated code.
    • An interesting note: the Java client won none of the benchmarks.

    I know that Java has many strengths, but speed isn't one of them. Looking at the results, we see the g++ runtimes are much more consistent than those of Java - on some tests, the Java Server is faster than the client by a factor of 20!? How could a programmer code without having any realistic expectation of the speed of his code. How embarrassed would you be to find that your "blazingly fast" app ran slower than molasses on the client machine, for reasons yet unknown?

    When it comes to speed, compiled languages will always run faster than interpreted ones, especially in real-world applications.

    But discussions of language speed are a moot point. What this really tested was the implementation, not the language. Speed is never a criteria upon which languages are judged - a "slow" language can always be brought up to speed with compiler optimizations (with a few exceptions). I suspect that if C++ was interpreted, and Java compiled, we'd see exactly the opposite results.

    In short, the value of a language consists not in how fast it runs, but in what it enables the programmer to do.

  • previous publications on the same topic by wdebruij (Score:2) Tuesday June 15 2004, @05:51PM
  • Study Might Be Flawed by xp (Score:1) Tuesday June 15 2004, @05:56PM
  • LEA! LEA! The guy's name is LEA! by fizzup (Score:2) Tuesday June 15 2004, @05:56PM
  • by Get Behind the Mule (61986) on Tuesday June 15 2004, @05:59PM (#9436155)
    Whew, there's seems to be a lot of denial running through this thread. "An interpreted language just can't possibly be as fast or faster as a compiled language! So I just don't care what the empirical results say, no matter how badly or well done they are, it just can't possibly be!"

    I think some of you are overlooking the fact that a VM running byte code is capable of doing optimizations that a compiled language just can't possibly do. A compiled language can only be optimized at compile time. Those optimizations may be very sophisticated, but they can never be any better than an educated guess about what's going to happen at runtime.

    But a VM is capable of determining exactly what is happening at runtime; it doesn't have to guess. And thus it is able to optimize those sections of code that really are, in true fact, impacting performance most severely. In can do this by compiling those sections to machine code, thus exploiting precisely the advantage that a compiled language is alleged to have by its very nature. And other kinds of optimizations, the kind that a compiler traditionally does, can be performed on those sections as well.

    Of course there are scenarios where runtime optimization doesn't win much, for example in a program that is run once on a small amount of data and then stopped, so that the profiler doesn't get much useful info to work with. This is why Java is more likely to have benefits like this in long-running server processes.

    And of course a conscientious C++ programmer will run a profiler on his program on a lot of sample data, and go about optimizing the slowest parts. A conscientious Java programmer should do that too. But an interpreted language has the advantage that the VM can do a lot of that work for you, and always does it at runtime, which is when it really counts.
  • Benchmarks... (Score:3, Insightful)

    by abertoll (460221) on Tuesday June 15 2004, @05:59PM (#9436156)
    (http://heroesonly.com/ | Last Journal: Tuesday June 15 2004, @04:34PM)
    A langauge in and of itself does not determine the speed. It's how that language is implemented/compiled. There's no reason why Java SHOULD be slower as long as it is compiled to the machine's architecture, and not to byte code. ... but then that destroys the purpose of Java.

    • Re:Benchmarks... by mlk (Score:1) Tuesday June 15 2004, @06:15PM
    • Java to Assembly (Score:4, Insightful)

      by HopeOS (74340) on Tuesday June 15 2004, @07:12PM (#9436823)
      It should also be mentioned that the java language requires specific overhead to be included that C++ and C do not. Even if compiled down to sleak assembly, Java is still saddled with doing bounds checking.

      The rest of the performance improvements are in the compiler optimizations and libraries which are mostly tangential to the language itself. If the compiler is clever enough to take "for (x=0, i=0; i<100; ++i) x+=5;" and substitute this for "x=500;", then great, but it should not be confused with an endorsement of the language itself.

      Furthermore, I had no difficulty modifying the C++ code to outperform or at least meet the results of the server-side JVM using G++. In the cases where Java had any lead whatsoever, the code was so trivial that the JVM could virtually precompute the result. I don't see this as being useful because in the real-world, nothing I write is so trivial that this is possible. If it was, I would have done it myself. I believe this largely explains the discrepency between these "tests" and my actual experience.

      -Hope
      [ Parent ]
  • Function calls (Score:5, Interesting)

    by BenjyD (316700) on Tuesday June 15 2004, @06:00PM (#9436176)
    Why does the example use a recursive fibonnaci sequence algorithm? It's so slow, and the runtime is dominated by the function call time.

    For example:

    [bdr@arthurdent tests]$ time ./fib_recurse 40
    165580141
    real 0m3.709s
    user 0m3.608s
    sys 0m0.005s

    time ./fib_for_loop 40
    165580141
    real 0m0.006s
    user 0m0.002s
    sys 0m0.002s

    I think a lot of these benchmarks are showing that the Hotspot optimiser is very good at avoiding function call overheads.
  • Here is an excerpt from the article for this story: Lea used G++ (GCC) 3.3.1 20030930 (with glibc 2.3.2-98) for the C++, with the -O2 flag (for both i386 and i686). He compiled the Java code normally with the Sun Java 1.4.2_01 compiler, and ran it with the Sun 1.4.2_01 JVM. He ran the tests on Red Hat Linux 9 / Fedora Test1 with the 2.4.20-20.9 kernel on a T30 laptop. The laptop "has a Pentium 4 mobile chip, 512MB of memory, a sort of slow disk," he notes.

    What this shows is that GCC's implementation of C++ is slower than an interpreted language like Java. This does not show that C++ is slower than Java.

    ----
    Notes on Stuff [blogspot.com]
  • Benchmarks? by slapout (Score:2) Tuesday June 15 2004, @06:04PM
    • 1 reply beneath your current threshold.
  • Java Faster Than C++? (Score:3, Funny)

    "Java Faster Than C++?"

    (/me runs screaming from soon-to-be-burning building)

    Is there something about flame-conducive subjects that make people want to "pick the scab", so to speak, or is it that sensitive subjects make people want to set stuff on fire? I think the Java vs. C++ holy wqar has even surpassed the EMACS vs vi one. (This is a good thing, I think, because arguing over vi vs. EMACS is a waste of time when it's clear that EMACS is better)

  • What about a contest? by TSTM (Score:1) Tuesday June 15 2004, @06:18PM
  • String concat sillyness (Score:5, Informative)

    by danharan (714822) on Tuesday June 15 2004, @06:21PM (#9436379)
    (Last Journal: Wednesday January 28 2004, @12:03AM)
    The article mentions Lea modified the String concatenation code, although Java still lost to C++ in that test. He unfortunately didn't do a great job:
    import java.io.*;
    import java.util.*;

    public class strcat {
    public static void main(String args[]) throws IOException {
    int n = Integer.parseInt(args[0]);
    StringBuffer str = new StringBuffer();

    for (int i=0; i<n; i++) {
    str.append("hello\n");
    }

    System.out.println(str.length());
    }
    }
    Instantiating the StringBuffer with an approximate size would prevent it from having to reassign a char array every time it runs out of space. new StringBuffer(n*6) for n=10000000 as used in his test should have a pretty large impact.

    I could not run the test for 10M, but ran it for up to 1M. 541 milliseconds in one case, 280 in the other. Here's the code I used (I had to modify the timing cause I'm running XP):
    public class Strcat2 {
    public static void main(String args[]) throws IOException
    {
    long start, elapsed;
    start = System.currentTimeMillis();

    int n = Integer.parseInt(args[0]);
    StringBuffer str = new StringBuffer(n*6);

    for (int i=0; i<n; i++)
    {
    str.append("hello\n");
    }

    System.out.println(str.length());
    elapsed = System.currentTimeMillis() - start;
    System.out.println("Elapsed time: "+elapsed);
    }
    }
    The only difference in the class Strcat besides the class name is the instantiation of StringBuffer.

    NB: I'm not accusing the author of bias against Java, nor am I ignorant of the fact a bunch of /.'ers could kick my ass in C++ optimization. It would be interesting however to have a distributed benchmark, where in the true spirit of OSS we could fiddle with it until we could not wring any more performance gains.
  • Where is "I Hate Java" Nathan "ncm" Myers? by nick_urbanik (Score:1) Tuesday June 15 2004, @06:21PM
  • -O3? by Kupek (Score:2) Tuesday June 15 2004, @06:23PM
    • Re:-O3? (Score:4, Informative)

      by BenjyD (316700) on Tuesday June 15 2004, @06:35PM (#9436515)
      Because -O3, despite what many people say, doesn't very often generate faster code. In many cases the extra inlining can create slower code.

      For example:

      methcall.cpp -O2 1.8s -O3 1.8s
      fib.cpp -O2 3.7s -O3 3.7s
      matrix.cpp -O2 1.8s -O3 1.8s (interestingly, adding -march=athlon-xp for my machine reduces time to 1.5s)
      [ Parent ]
      • Re:-O3? by Kupek (Score:2) Tuesday June 15 2004, @06:47PM
      • Re:-O3? by dtfinch (Score:2) Wednesday June 16 2004, @02:25AM
        • Re:-O3? by BenjyD (Score:2) Wednesday June 16 2004, @02:51AM
      • 1 reply beneath your current threshold.
    • Re:-O3? by Kupek (Score:2) Tuesday June 15 2004, @06:39PM
  • who cares by Xiaus (Score:1) Tuesday June 15 2004, @06:24PM
    • Re:who cares by thepr0fess0r (Score:1) Tuesday June 15 2004, @08:49PM
  • I don't know about Java, but... by callipygian-showsyst (Score:1) Tuesday June 15 2004, @06:26PM
  • Could C++ compile to Java bytecode? by NoMercy (Score:2) Tuesday June 15 2004, @06:36PM
  • Timing strategies (Score:3, Interesting)

    by Adruab (784669) on Tuesday June 15 2004, @06:48PM (#9436641)

    First of all, the C++ was crappy as many people pointed out.

    Second of all, I'm sure that loading the C++ program takes some time more than just loading the byte codes (though that's probably mitigated somewhat by the byte code translation).

    Third, the optimization options he used for gcc are a joke. -march=i686 is not even relevant to much larger platforms that can benefit from other optimizations.

    And, 4th, and this is the big one, this guy does not know how to benchmark. Anyone who has actually benchmarked their own application knows that if you want to figure out how fast something is, you have to time it IN THE PROGRAM!!!! This would avoid allocation/cout/unnecessary function overhead, when all you're trying to test is a specific operation. I BET (and at some point I will test this) that if you used timing mechanisms INSIDE the programs, that C++ would come out much faster, with the exception of object management and memory stuff (excepting garbage collecting...). Even then, much of that stuff can be overcome by memory pooling, which a surprising number of people ignore.

    Until someone does something like all these language comparisons are totally pointless because you are NOT ACTUALLY BENCHMARKING the topic you are looking at. Please lets have someone be intelligent about this for once....

  • Obligatory Bash Quote... (Score:4, Funny)

    by MP3Chuck (652277) on Tuesday June 15 2004, @06:49PM (#9436645)
    (http://www.tempusband.com/ | Last Journal: Friday August 29 2003, @07:54PM)
    http://bash.org/?338364 #338364 +(1308)- [X] Saying that Java is nice because it works on all OS's is like saying that anal sex is nice because it works on all genders
  • Java Machine WAY faster then C++ by cryptoluddite (Score:1) Tuesday June 15 2004, @06:52PM
  • Ah, C++ ... by Crispin Cowan (Score:1) Tuesday June 15 2004, @06:58PM
  • *sigh* by ldspartan (Score:1) Tuesday June 15 2004, @07:10PM
    • Re:*sigh* by slandis (Score:1) Tuesday June 15 2004, @09:02PM
      • Re:*sigh* by ldspartan (Score:1) Tuesday June 15 2004, @09:20PM
        • Re:*sigh* by slandis (Score:1) Tuesday June 15 2004, @10:15PM
  • Java == modern COBOL by NotZed (Score:2) Tuesday June 15 2004, @07:10PM
  • by Serveert (102805) on Tuesday June 15 2004, @07:11PM (#9436816)
    sprintf(buf, "%x", i);

    It must parse the "%x" and determine what it's trying to do. So it decides, at runtime, you want to translate an integer value into a hexidecimal string. Of course if there's an error at runtime in the string "..." it must generate an error. How 'bout using strtol?

    Now let's look at the java version:

    Integer.toString(i, 16)

    Ok, here we have something that is strongly typed so of course it will be faster. At runtime the java compiler _knows_ what it's dealing with and it knows it must invoke the hexadecimal conversion code.

    Note that these statements are within loops.

    Just one example, that was the first file I looked at. I don't think they have quite optimized the C++ code IMO. Plus the C++ library is notoriously slow, I would recommend rogue wave or your homegrown C++ classes.

    I think the lesson here is it's very easy to write slow C++ code while it's very easy to write fast Java code.

    Gimme any C++ code here and I'll profile it/speed it up and get it as fast if not faster than java.
  • by eduardodude (122967) on Tuesday June 15 2004, @07:25PM (#9436935)
    (http://slashdot.org/)
    Check out this recent IBM Developerworks article [ibm.com] which looks at how modern JVMs handle allocation and garbage collection.

    Some very surprising tidbits there. For instance:

    "Performance advice often has a short shelf life; while it was once true that allocation was expensive, it is now no longer the case. In fact, it is downright cheap, and with a few very compute-intensive exceptions, performance considerations are generally no longer a good reason to avoid allocation. Sun estimates allocation costs at approximately ten machine instructions. That's pretty much free -- certainly no reason to complicate the structure of your program or incur additional maintenance risks for the sake of eliminating a few object creations."

    Read the article for an excellent nuts-and-bolts analysis of many current performance considerations. From the posts in this thread, it's pretty clear a lot of people haven't looked into what's actually done in a server JVM these days.
  • However, C++ is faster to LEARN than java by RLiegh (Score:2) Tuesday June 15 2004, @07:32PM
  • Client JVM by Brandybuck (Score:2) Tuesday June 15 2004, @07:42PM
  • Convergence by Renaissance 2K (Score:1) Tuesday June 15 2004, @07:44PM
    • 1 reply beneath your current threshold.
  • C++ 60X Faster Than Java by Zan Lynx (Score:2) Tuesday June 15 2004, @07:50PM
  • 1.5 JVM improvements likely to impact speed by eduardodude (Score:1) Tuesday June 15 2004, @07:54PM
    • 1 reply beneath your current threshold.
  • Lies, damn lies... by Tracy Reed (Score:2) Tuesday June 15 2004, @07:57PM
  • I wish I could USE Java for anything real by pabtro (Score:1) Tuesday June 15 2004, @08:03PM
  • Speed bigots! by t'mbert (Score:1) Tuesday June 15 2004, @08:13PM
  • awful presentation by boots@work (Score:2) Tuesday June 15 2004, @08:28PM
  • Truely optimized c++ code by nukem996 (Score:1) Tuesday June 15 2004, @08:49PM
  • Come on, come on... by Lucky Luc (Score:1) Tuesday June 15 2004, @08:51PM
  • I'm getting too old for this crap by Prong (Score:1) Tuesday June 15 2004, @09:00PM
  • laughing.. by joeldg (Score:2) Tuesday June 15 2004, @09:47PM
  • Given infinite time C/C++ is faster by Ambassador Kosh (Score:2) Tuesday June 15 2004, @09:52PM
  • Study Already Performed by Joeseph Kaylor by Dozix007 (Score:2) Tuesday June 15 2004, @10:58PM
  • outdated claim by TheLittleJetson (Score:2) Tuesday June 15 2004, @11:00PM
  • at risk of sounding like microsoft... by smash (Score:2) Tuesday June 15 2004, @11:28PM
  • jEdit vs. Emacs by mr_data_esq (Score:1) Tuesday June 15 2004, @11:43PM
  • GNU STL not commercial quality by LonelyKindGuy (Score:1) Tuesday June 15 2004, @11:44PM
  • Apples? Oranges? How *should* we comapre them? by Trinition (Score:2) Tuesday June 15 2004, @11:47PM
  • Am I missing something here? by ad0le (Score:1) Wednesday June 16 2004, @12:13AM
  • Why? by magerquark.de (Score:1) Wednesday June 16 2004, @12:54AM
  • Sure Java might be faster by dtfinch (Score:2) Wednesday June 16 2004, @01:44AM
  • Regarding Object Creation benchmark by gsasha (Score:1) Wednesday June 16 2004, @01:46AM
  • by mc6809e (214243) on Wednesday June 16 2004, @02:18AM (#9439470)
    I notice that much of the overhead is simply in making function calls.

    Ackermann.cpp, for example, spends very little time actually calculating anything. Much of it's work includes all the overhead associated with making a function call.

    Included in this overhead is management of the frame pointer. By using -fomit-frame-pointer, you avoid pushing the old ebp on the stack and a store of the current esp into ebp.

    Ackermann runs about twice as fast with this simple optimization.

  • Bullshit (Score:3, Insightful)

    by baest (763283) on Wednesday June 16 2004, @02:19AM (#9439479)

    I saw this test a few days ago and wanted to check it out. The first thing I realize is that the source code is somewhat different even if Java has almost the same syntax as C++.

    I understand that System.out.println(); is not in C++ but why have

    return(M ? (Ack(M-1,N ? Ack(M,(N-1)) : 1)) : N+1);
    instead of
    return (m == 0) ? (n + 1) : ((n == 0) ? Ack(m-1, 1) : Ack(m-1, Ack(m, n - 1)));

    I made the C++ code look like Java and got a 15% save. Problably even more if I had increased the number you call the program with. I looked at some of the other program and they have different code in them as well. So this test is bullshit it only shows that you can make slow programs in any language.

    • Re:Bullshit by baest (Score:1) Wednesday June 16 2004, @02:35AM
  • Let's see the primes thing again :-) by RedlumF (Score:2) Wednesday June 16 2004, @02:58AM
  • Post review by strider_starslayer (Score:2) Wednesday June 16 2004, @03:01AM
  • If you want slow... by dave1791 (Score:1) Wednesday June 16 2004, @03:44AM
  • Is the performance that big a deal? by jochend (Score:1) Wednesday June 16 2004, @05:12AM
  • All relative by javajoe99 (Score:1) Wednesday June 16 2004, @07:39AM
  • Grain of salt, anyone? by huckamania (Score:1) Wednesday June 16 2004, @08:06AM
  • its not the code... its the JVM by locutus2k (Score:1) Wednesday June 16 2004, @08:08AM
  • stop the nonsense, moron! by Anonymous Coward (Score:1) Wednesday June 16 2004, @08:16AM
  • Has anyone else realized.... by kook04 (Score:1) Wednesday June 16 2004, @08:19AM
  • What's important to note is that the differences introduced by the VM and the rest of Java's overhead are small enough now that, for headless applications, poor coding can easily bridge the difference. There's no huge, glaring, a priori reason to use C++ over Java for headless apps, and when you want your server code to be portable crossplatform you'll find a huge, glaring reason to use Java.

    Now what this study obviously doesn't deal at all with GUI'd applications, and Sun's Swing in particular does nothing to help Java's reputation as a slow technology. There's a relatively interesting discussion at java.net called Swing Usability [java.net] that points out some of these shortcomings. What the Swing team doesn't seem to understand is that slower than native means slow to most users.

    And just like the comments in this thread point out, as long as you put a compatibility layer between code and execution, you're going to be slower by definition. With Swing, simple to overlook unoptimized coding practices do not easily spell the difference between implementations. Here, Java's speed and performance is visibly slower no matter how quickly the GUI-less logic behind is racing along. (Yes, SWT is a big help, but it's not part of the JDK and likely still won't be seen in, say, Limewire [limewire.com] any time soon.)
  • Why not try a REAL WORLD comparison? by DreamCoder (Score:1) Wednesday June 16 2004, @01:23PM
  • Re:If you don't run the JVM... (Score:5, Informative)

    by Tar-Palantir (590548) on Tuesday June 15 2004, @04:31PM (#9435039)
    He claims you should use the server JVM instead, stating that it is faster but slower to startup and consumes more memory.
    [ Parent ]
  • True, which is why the eclipse project (www.eclipse.org) created and maintains SWT. A portable native widget tookit. See http://www.eclipse.org/articles/Article-SWT-Design -1/SWT-Design-1.html for more info.
    [ Parent ]
  • Re:my arse (Score:3, Funny)

    by kaffiene (38781) on Tuesday June 15 2004, @04:33PM (#9435087)
    "My arse" is a good name for this post since that's obviously where your head is stuck - much like the rest of the /. morons with their anti-java-no-matter-what stance.

    I used to be a C hacker and a laughed at Java when it came out because of it's poor performance. Times have changed, but the language bigots haven't.
    [ Parent ]
    • Re:my arse by Anonymous Coward (Score:1) Tuesday June 15 2004, @04:36PM
      • Re:my arse (Score:5, Informative)

        by kaffiene (38781) on Tuesday June 15 2004, @04:40PM (#9435203)
        *sigh* have you people never heard of runtime optimisations? There are some things you can optimise at runtime (like runtime constants) which are *impossible* to optimise at compile time.

        This whole "x is written in y, so x can't be faster than y" rubbish is just that - rubbish.
        [ Parent ]
        • Re:my arse by sjf (Score:1) Tuesday June 15 2004, @05:24PM
          • Re:my arse by kaffiene (Score:1) Tuesday June 15 2004, @09:45PM
        • Re:my arse by cardshark2001 (Score:2) Wednesday June 16 2004, @01:47PM
          • Re:my arse by kaffiene (Score:1) Wednesday June 16 2004, @05:05PM
          • Re:my arse by Trinition (Score:2) Wednesday June 16 2004, @06:55PM
            • Re:my arse by cardshark2001 (Score:2) Wednesday June 16 2004, @10:29PM
              • Re:my arse by Trinition (Score:2) Thursday June 17 2004, @05:42AM
          • 1 reply beneath your current threshold.
    • Re:my arse by kaffiene (Score:1) Tuesday June 15 2004, @04:45PM
      • 1 reply beneath your current threshold.
    • 1 reply beneath your current threshold.
  • Re:Sorry, no. (Score:5, Funny)

    by Ianoo (711633) on Tuesday June 15 2004, @04:34PM (#9435096)
    (Last Journal: Friday May 21 2004, @10:08AM)
    I think you're missing the point. I bet 19 seconds of that execution time was the start-up and shutdown of the virtual machine. As the program gets bigger and bigger, this becomes less and less significant.
    [ Parent ]
    • Re:Sorry, no. by SoCalChris (Score:2) Tuesday June 15 2004, @04:50PM
      • 1 reply beneath your current threshold.
    • Re:Sorry, no. (Score:4, Interesting)

      by afidel (530433) on Tuesday June 15 2004, @05:02PM (#9435509)
      No, it doesn't. Check out WordPerfect Java, Novell ConsoleOne, or any other large Java project for a real world counter example. Java applications are slow to load for any meaningfull piece of client side software. Java works wonderfully for middleware applications but is simply the wrong tool for client side software. When I can reboot the computer and load MCC faster than I can start ConsolOne there is something seriously amiss (and no jokes about having to reboot, I have windows PC's with 200 day uptimes limited only by patching sessions, which is true for any properly maintained OS).
      [ Parent ]
      • Re:Sorry, no. by jarich (Score:2) Tuesday June 15 2004, @07:50PM
      • Re:Sorry, no. by Trinition (Score:2) Wednesday June 16 2004, @07:03PM
      • 1 reply beneath your current threshold.
    • Re:Sorry, no. by 0x0d0a (Score:1) Tuesday June 15 2004, @06:29PM
      • Re:Sorry, no. by pdbaby (Score:1) Tuesday June 15 2004, @08:56PM
      • Re:Sorry, no. by jmccay (Score:2) Tuesday June 15 2004, @09:44PM
      • Re:Sorry, no. by dasmegabyte (Score:2) Tuesday June 15 2004, @10:52PM
        • Re:Sorry, no. by excessive (Score:1) Wednesday June 16 2004, @10:21AM
      • Re:Sorry, no. by 0x0d0a (Score:2) Tuesday June 15 2004, @09:54PM
        • Re:Sorry, no. by mmusson (Score:1) Wednesday June 16 2004, @12:16AM
      • 1 reply beneath your current threshold.
  • by mark-t (151149) <markt.lynx@bc@ca> on Tuesday June 15 2004, @04:34PM (#9435103)
    (Last Journal: Tuesday September 12 2006, @03:31PM)
    You haven't played with the pluggable look and feel for Swing much, have you?

    Oh... and as of Java1.5, Swing apps can now be skinned to look however you'd like them to.

    [ Parent ]
  • Re:Sorry, no. by mveloso (Score:2) Tuesday June 15 2004, @04:34PM
  • Re:Sorry, no. by SpaceCadetTrav (Score:1) Tuesday June 15 2004, @04:34PM
  • by saden1 (581102) on Tuesday June 15 2004, @04:35PM (#9435119)
    I&#146;m sorry but someone who says "I've never been very good at decoding GCC's error messages" is not competent enough to perform performance comparison. This performance test is a shame and shouldn&#146;t be taken seriously.
    [ Parent ]
  • Re:Sorry, no. by Morgahastu (Score:2) Tuesday June 15 2004, @04:35PM
    • Re:Sorry, no. by vsprintf (Score:2) Tuesday June 15 2004, @07:34PM
  • That just means... (Score:3, Interesting)

    by SuperKendall (25149) * on Tuesday June 15 2004, @04:35PM (#9435131)
    You were running Swing with the Windows L&F.
    [ Parent ]
  • This might be funny, but it isn't informative. by John Harrison (Score:2) Tuesday June 15 2004, @04:36PM
  • Re:Sorry, no. by bckrispi (Score:2) Tuesday June 15 2004, @04:37PM
  • Re:This doesn't make any sense... (Score:5, Informative)

    by Ianoo (711633) on Tuesday June 15 2004, @04:37PM (#9435160)
    (Last Journal: Friday May 21 2004, @10:08AM)
    Java isn't "emulation". Modern JVMs use a JIT (just-in-time compiler) to translate bytecode instructions into pure binary assembled object code just before it is reached in the program (hence "just in time"). This is cached, so the next time that particular code is executed, it will run at full assembler speed.

    Something I've often wondered is whether this caching could be persistent, i.e. be kept between runs of the JVM. Eventually, the entire program would be translated to pure assembler with the cost of translation largely amortised across many sessions. You still keep the safety, cross platform compatibility and ease-of-programming of a bytecode language (i.e. Java, C#) but you get the bonus of the cached object code being just as fast, even during startup and shutdown.
    [ Parent ]
  • Re:Sorry, no. by kaffiene (Score:2) Tuesday June 15 2004, @04:37PM
    • Re:Sorry, no. by stratjakt (Score:1) Tuesday June 15 2004, @04:43PM
      • Re:Sorry, no. by bckrispi (Score:2) Tuesday June 15 2004, @04:47PM
        • Re:Sorry, no. by Mr Tall (Score:1) Tuesday June 15 2004, @05:05PM
      • Re:Sorry, no. by mattyrobinson69 (Score:1) Tuesday June 15 2004, @06:13PM
        • Re:Sorry, no. by mattyrobinson69 (Score:1) Wednesday June 16 2004, @09:33AM
        • 1 reply beneath your current threshold.
  • One of the best things about OS X is Aqua-ized Java apps.

    http://developer.apple.com/documentation/Java/Co nc eptual/Java141Development/UI_Toolkits/chapter_5_se ction_2.html
    [ Parent ]
  • Sorry, yes by Anonymous Coward (Score:1) Tuesday June 15 2004, @04:37PM
  • Provide link please! (Score:3, Insightful)

    by 3770 (560838) on Tuesday June 15 2004, @04:40PM (#9435210)
    (http://vsxgen.sourceforge.net/)
    Please point me to a source which verifies your claim.
    [ Parent ]
  • Re:Sorry, no. (Score:5, Interesting)

    by shadowmatter (734276) on Tuesday June 15 2004, @04:40PM (#9435211)
    First, it's been known for awhile that Java is a poor performer when writing to the console, for whatever reason. Second, your Java timing probably include the time to startup the VM (not that this is wrong).

    If you have a program that runs for awhile (so the startup time is small compared to the time the program takes to run), and does not do intensive output to the console, then Java is a reasonable choice in my opinion. Combined with SWT, Java applications can be quite snappy (see Eclipse, Azureus), and the end user will probably never know the difference.

    - shadowmatter
    [ Parent ]
  • Re:every year this happens... (Score:4, Informative)

    by bckrispi (725257) on Tuesday June 15 2004, @04:41PM (#9435229)
    Ummm, wrong. The majority of java class libraries, and (significant parts, if not all) of the compiler are written in Java. There is, of course, some C++ for doing really low level stuff, but not the amount that you're implying.
    [ Parent ]
    • The compiler by SteamyMobile (Score:1) Tuesday June 15 2004, @04:56PM
    • 1 reply beneath your current threshold.
  • Re:Nort really surprising (Score:5, Insightful)

    by pclminion (145572) on Tuesday June 15 2004, @04:42PM (#9435236)
    Talk about an unfair comparison... The C++ example uses the standard IO library, while the C example uses the UNIX write() call. Of course there's going to be overhead associated with using a buffered IO layer.

    This would be much more meaninful if you had used fputs() instead of write() in the C version.

    As for "several orders of magnitude," I call bullshit. There's no way in hell the standard C++ IO functions are hundreds of times slower unless they're extremely badly written. Which leads me to another reason why this example sucks: there can be different implementations of the standard libraries.

    In conclusion, this "comparison" is a stinky pile of shit, and should be ignored. And it's not even on topic, since it doesn't have a Java version.

    [ Parent ]
  • Re:every year this happens... by Citizen of Earth (Score:2) Tuesday June 15 2004, @04:43PM
  • been there, done that (Score:5, Informative)

    by Anonymous Coward on Tuesday June 15 2004, @04:43PM (#9435245)
    1) javac (Sun's Java compiler) is written in Java. You can even access it programmatically at runtime if you really want to.

    2) While it's not an id game, IL2 Sturmovik [il2sturmovik.com] is a critically-acclaimed fight simulator that was written almost entirely in Java.
    [ Parent ]
  • Re:Caught up with the speed, but still the ugliest by rms_nz (Score:1) Tuesday June 15 2004, @04:44PM
  • by Pac (9516) <paulo...candido@@@gmail...com> on Tuesday June 15 2004, @04:44PM (#9435264)
    Out of the box Swing is amazingly ugly. The people choosing default colors at Sun could well be substituted by a randomizer without a difference in results. I mean, who was the genius who thought purple bars in a menu were cute?

    Now, when you need to change that quickly and without much overload, there are ways. A little known global HashTable called UIDefaults lets you change just about everything on the visual interface without having to write your own LookAndFeel (which you obviously can do too, for very large projects). You can have your scrollbars, menus, etc in any colour, size and shape, using any font. You can easily change all default colours without having to set every control. After a while the ugliness ceases to be a problem.
    [ Parent ]
  • by I_Love_Pocky! (751171) on Tuesday June 15 2004, @04:46PM (#9435284)
    (Last Journal: Saturday March 06 2004, @01:00AM)
    All you programmers that say you can do anything in Java/C#/etc are terrible.

    Actually you can do most anything in those languages. Although for performance, and desgin reasons you may wish to use something else depending on the application.

    You have no respect for code. Learn assembly and then we'll talk.

    I know assembly, and fun as it is, it isn't well suited for high level projects where code reuse and mantainability are important. By the way, I have no respect for someone who knows assembly and thinks it is difficult. It isn't. And it certainly isn't graceful or elegant, but I love it all the same.
    [ Parent ]
  • by Sebastopol (189276) on Tuesday June 15 2004, @04:46PM (#9435290)
    (http://slashdot.org/)
    "It's always been written in Java."

    Except for the first Java compiler. ;P
    [ Parent ]
  • Just-in-time compilation by Anonymous Coward (Score:1) Tuesday June 15 2004, @04:47PM
  • Re:every year this happens... (Score:5, Insightful)

    by Erwos (553607) on Tuesday June 15 2004, @04:47PM (#9435305)
    I believe that Sun's javac bootstraps itself just like gcc does. That would be your java compiler written in Java.

    _Jikes_, OTOH, is written in C++. But that's not really the official Java compiler by a long shot.

    Your second requirement is absolutely bizarre. Does this mean you're not taking languages like Lisp, Prolog, Python, and Perl seriously, too? Those are all very nice languages for doing stuff in, but I'm pretty sure id never wrote a 3D engine in them. In fact, I was under the impression that id has never written a 3D engine in C++, either. Should we not take C++ seriously?

    IMHO: The measure of a language is not how easy it is to write an arbitrary application in it. It's how easy it is to write something for which the language was designed to do.

    -Erwos
    [ Parent ]
  • Re:Caught up with the speed, but still the ugliest by DeckerEgo (Score:2) Tuesday June 15 2004, @04:47PM
  • Re:every year this happens... by Mornelithe (Score:2) Tuesday June 15 2004, @04:47PM
  • Re:Caught up with the speed, but still the ugliest by Anonymous Coward (Score:1) Tuesday June 15 2004, @04:49PM
    • 1 reply beneath your current threshold.
  • Re:Sorry, no. by Demandred (Score:1) Tuesday June 15 2004, @04:49PM
  • Re:Caught up with the speed, but still the ugliest by ci4 (Score:1) Tuesday June 15 2004, @04:50PM
  • one out of two..... by MarkEst1973 (Score:1) Tuesday June 15 2004, @04:51PM
  • Re:Nort really surprising by IMarvinTPA (Score:2) Tuesday June 15 2004, @04:52PM
  • In Hardware? by gerf (Score:2) Tuesday June 15 2004, @04:52PM
  • Re:Sorry, no. (Score:3, Interesting)

    by Knight2K (102749) on Tuesday June 15 2004, @04:52PM (#9435377)
    (http://slashdot.org/)
    One X-factor is JVM warm up. When benchmarking Java you should run the test multiple times in the same VM. This gives you a better real-world feel of what a Java app will do during continuous use, at least from a server perspective.

    Desktop app use cases may be different, in which case your test may be valid. Start-up time is definitely a significant part of the user experience. At one point Java 1.5 was supposed to have shared VMs, so that Java can start at system load time. Other VMs would just then be a matter of forking another process off the already running VM, thus increasing startup time. My understanding is this has fallen off the truck for that release, but people are working on it.
    [ Parent ]
  • Re:Largest Prime (Score:3, Informative)

    by jfengel (409917) on Tuesday June 15 2004, @04:54PM (#9435408)
    (http://slashdot.org/ | Last Journal: Monday November 03 2003, @03:59PM)
    I know you're joking to make a point, but you do realize that 1 isn't prime [utah.edu], right? That's not just a matter of arbitrary definitions; a lot of theorems that apply to primes don't apply to 1.
    [ Parent ]
  • by kaffiene (38781) on Tuesday June 15 2004, @04:55PM (#9435428)
    For years it was "Java is too slow" Now it's too ugly??

    Sheesh.

    I'm sure one of Swing (with it's several different look and feels and skinnable interface) or SWT or AWT will fit the bill.
    [ Parent ]
  • Re:every year this happens... by ky11x (Score:1) Tuesday June 15 2004, @04:55PM
  • Re:every year this happens... by kaffiene (Score:1) Tuesday June 15 2004, @04:59PM
  • Re:Sorry, no. (Score:4, Interesting)

    I'm inclined to agree with you, except that the benchmarks were qualified as talking about being relevant to enterprise applications. In such a situation, run-time optimizations are critical.

    While it is entirely possible [in c/c++] to use a profiler to generate compiler hints so as to generate even more efficient code, this is rarely performed, and often is not free. A VM otoh does get this capability for free.

    Additionally, the java memory manager has a slight edge over tradditional malloc's for total throughput (though the best throughput configurations have horrible spuradic response times). It is also possible to choose a different memory manager for c/c++, but this too is rarely used.. Moreover, it is much harder to have 3'rd party code integrate well with a garbage-collector model. Java enforces garbage collection, and thus optionally gets the particular performance gains (being free to trade off throughput for responsiveness no matter what 3'rd part code is integrated).

    As was pointed out, one of the strenghts of C/C++ are pass-by-value, which allows memory allocations to be avoided all-together, but at the cost of copy-time and robustness of code. If a method call requires instantiation, c/c++ have the option of passing in a local [stack resident] structure to be populated by the method. However, this is fodder for buffer-overflow exploits, and notorious for otherwise bad code (accidently caching the address of a value that lives on the stack). Thus, given that c++ will use "new" and thus generally perform a malloc, the same performance issues above apply, and c/c++ may have the additional overhead of copy-by-value.

    The fact that you have to explicity declare a c++ parameter as pass-by-reference suggests that those interested in "good programming practices" (tm) will only make a pass-by-reference if you intend to modify it's contents. Thus "clean" code in c++ will be copy-intensive... For fairness, clean java code should always make immutable wrappers for any non-modifyable code, thus requiring an all together different liability (and thus I can't make any claims as to which would be faster; wrapper object instantiation or deep parameter-copy). Though all primatives are available in java as immutable objects (Strings, Dates, etc). Moreoever, clean OO-code should always use method getters, and make all fields private (not even protected). Both C++ and jit'd java can inline these getters.

    I haven't looked at the benchmark code, but the above are common components which make a big difference when scaling to large enterprise applications, or even when merely writing a glue application which integrates many large 3'rd party libraries. In c++ you don't have a lot of control over the 3'rd party libraries (in terms of their design trade-offs), but with a VM, you are largely sheltered and have many configurable alternatives.
    [ Parent ]
    • Re:Sorry, no. by kraut (Score:3) Tuesday June 15 2004, @06:02PM
      • Re:Sorry, no. by maraist (Score:3) Tuesday June 15 2004, @07:30PM
      • 1 reply beneath your current threshold.
    • Re:Sorry, no. by jeremyp (Score:2) Wednesday June 16 2004, @11:04AM
  • Re:Java is still pants... by fr0dicus (Score:2) Tuesday June 15 2004, @05:25PM
  • Re:Sorry, no. (Score:5, Funny)

    by phasm42 (588479) on Tuesday June 15 2004, @05:52PM (#9436085)
    I just wrote two programs to count to 1 billion. The one written in C took 2.4 seconds, the one written in assembly took 0.85 seconds. Wow, assembly is so much faster. My in-depth analysis of these two languages has shown once and for all that all us high-level language suckers need to get back to coding in assembly and quit this HLL foolishness.
    [ Parent ]
    • Re:Sorry, no. by Anonymous Coward (Score:1) Tuesday June 15 2004, @07:48PM
      • Re:Sorry, no. by maxwell demon (Score:3) Tuesday June 15 2004, @11:06PM
    • Re:Sorry, no. by sploxx (Score:2) Wednesday June 16 2004, @03:37AM
  • Actually, you're wrong, at least in part. Due to lack of specificity, I'd say that invalidates your argument.

    It's all about *where* and *how* Java is used.

    As someone who has done application development with both Java and C++ (as well as C, and others), here is how it works (assuming equivalent levels of code quality regardless of language):

    For a non-GUI application, Java can be made to run nearly as fast as C++, with a slight startup penalty, and while utilizing decidedly more RAM.

    For a GUI applicaton, Java will run considerably slower than a C++ application, and use significantly more RAM.

    What does this mean?

    Java works great for back-end applications, for web applications, etc. Especially if you take into consideration it's startup penalty (time needed to start the JVM) and run your java program persistently, Java can definitely be fast enough for this.

    As for GUI applications, Java is only an ideal choice if you absolutely need something that is fully cross-platform (without using multiple binaries for each), for small applications, or for situations where you can gaurantee that the client machine will have a LOT of RAM, and a fairly modern CPU.

    Now, use which ever langauge makes the most sense for what you're doing, and let's get back to coding, okay?
    [ Parent ]
  • Re:every year this happens... by RedWizzard (Score:2) Tuesday June 15 2004, @06:09PM
  • Re:Java may be fast but ... by bgoss (Score:1) Tuesday June 15 2004, @06:11PM
  • Re:this is a joke by kendoka (Score:1) Tuesday June 15 2004, @06:24PM
  • Java might have finally caught up with the speed, but Swing is still the ugliest GUI out there.
    SWING performance didn't catch up to anything. SWING and SWT are still FAR slower than QT or the Win32 API but a long, longshot. SWING especially is absurdly, stupidly slow.

    Non-graphical Java code can indeed be very competitive with other languages, but it would help if the author bothered to implement the code for his tests intelligently.
    The Fibonacci code is recursive, which is about the slowest possible way to implement it, and much of the other code uses high-level features of C++ which are a convenience for the programmer, but are not used when worried about speed.

    This fibo code, for example, should be faster:
    const int max = 1000;

    void fibonacci (unsigned long num)
    {
    int fn = 1, fibo_array[max] = { 0 };
    fibo_array[0] = 1;
    cout << "1 ";
    {
    for(int i = 1 ; i < num ; i++)
    {
    cout << fn << ' ';
    fibo_array[i] = fn;
    fn += fibo_array[i-1];
    }
    }
    return;
    }
    This code was turned in by a student in a lab of mine. This was his first semester in CS, and this code outperforms the Java code quoted on the website considerably. (Try it!).

    I am not saying that recursion and high-level C++ features should NOT be used, but I AM saying that if you are comparing the potential speed of languages, you should use tricks that each language provides to optimize speed.

    Java will never be faster than properly optimized C++ compiled with an intelligent optimizing compiler except in bizarre corner cases, and tests like this are not terribly convincing demonstrations otherwise. Even the corner cases are removed by a sufficiently talented programmer.
    This is also not to say that Java is bad. I think Java is a great language (except for GUI programming with SWING), and definitely makes many programming tasks faster to code and easier to debug than one can do in C++.
    [ Parent ]
  • Re:Caught up with the speed, but still the ugliest by SparafucileMan (Score:1) Tuesday June 15 2004, @07:49PM
    • 1 reply beneath your current threshold.
  • Re:Narcoticized slug faster than SR71 by 09za+ (Score:1) Tuesday June 15 2004, @11:48PM
  • Congratulations by GunFodder (Score:2) Wednesday June 16 2004, @12:04AM
  • Apples to Apples please by davegust (Score:2) Wednesday June 16 2004, @12:32AM
  • Re:GCC 3.4 Significantly Faster. by cimetmc (Score:1) Wednesday June 16 2004, @03:36AM
  • Re:Java sucks, pass it on by mrshowtime (Score:1) Wednesday June 16 2004, @05:31AM
  • Re:This is Not Good News by 09za+ (Score:1) Wednesday June 16 2004, @07:35AM
  • Re:Sorry, no. by sulli (Score:2) Wednesday June 16 2004, @12:01PM
  • 62 replies beneath your current threshold.
(1) | 2