Slashdot Mirror


Java Faster Than C++?

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

1,270 comments

  1. Um, it's online by JoshuaDFranklin · · Score: 5, Informative
    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

    1. Re:Um, it's online by jdhutchins · · Score: 4, Insightful

      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.

    2. Re:Um, it's online by Too+Much+Noise · · Score: 3, Informative

      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.

    3. Re:Um, it's online by mukund · · Score: 3, Informative

      Your wish just came true. Check out the JNode project.

      --
      Banu
    4. Re:Um, it's online by poot_rootbeer · · Score: 3, Insightful

      until one can write an OS kernel in it, Java is still not what I would personally look to for the future of software development.

      That's a silly thing to say.

      How many OS kernels are going to be written in the next ten years? And how many business applications? And the ratio of the latter to the former is what, 10,000 to 1?

    5. Re:Um, it's online by cheesybagel · · Score: 4, Informative
      I just looked at hash (C++, Java), 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.

    6. Re:Um, it's online by Anonymous Coward · · Score: 5, Informative

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

    7. Re:Um, it's online by Halfbaked+Plan · · Score: 1

      I guess it depends on who your boss is.

      Plug along with your 'business applications' by all means.

      --
      resigned
    8. Re:Um, it's online by cheesybagel · · Score: 1
      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.

      Heh. I really need to get some sleep.

    9. Re:Um, it's online by Bingo+Foo · · Score: 1

      Not to mention the tests which C++ wins even in his, um, differently biased conditions: Nested loops and matrix multiplication. I may be a special case, but more than half of the codes I write have matrix multiplication; all of them have nested loops.

      --
      taken! (by Davidleeroth) Thanks Bingo Foo!
    10. Re:Um, it's online by PhrostyMcByte · · Score: 1
      Haha, look at the guys hash table benchmark (hash.cpp)
      for (int i=1; i<=n; i++) {
      sprintf(buf, "%x", i);
      X[strdup(buf)] = i;
      }

      int c = 0;
      for (int i=n; i>0; i--) {
      sprintf(buf, "%d", i);
      if (X[strdup(buf)]) c++;
      }
      Yay memory leaks! Why is he using C strings for the compare? std::string is surely faster because it already knows length. I think a lot of implementations have a specialized hash_map for string also.
    11. Re:Um, it's online by Tranzig · · Score: 2, Informative

      The second loop is traversed backwards in the C++ version while it is not in the Java version. Don't ask me why.

      There is an instruction called loop in the x86 instruction set which decreases the value of the register cx by 1 on every iteration, until it becomes 0. So by writing decrementing for loops, it could be transformed to a mov and a loop. Two decades ago it was faster than increasing a variable, checking if it reached the required value and if it's less then jumping to the begining.
      But nowadays x86 processors work different, and loop became slower than the jumping method. It seems the writer of this code forgot this one. Anyways, the optimizing compilers don't generate loop instructions for decrementing for loops anymore.

    12. Re:Um, it's online by kin_korn_karn · · Score: 2, Funny

      Yes sir, Professor Knuth.

    13. Re:Um, it's online by TheRealMindChild · · Score: 1

      You mean like JNode?

      --

      "When life gives you lemons, don't make lemonade. Make life take the lemons back!" -- Cave Johnson
    14. Re:Um, it's online by NoMercy · · Score: 1

      Tbough I've just come out of university I definately heard a few years ago of someone trying to write a OS in Java, though arguably the OS would be the JVM and the Java just a abstraction layer to it.

    15. Re:Um, it's online by Anonymous Coward · · Score: 0

      Nice memory leak. strdup

    16. Re:Um, it's online by Anonymous Coward · · Score: 0

      Just don't use this browser to read it because its too slow.

    17. Re:Um, it's online by Tony-A · · Score: 1

      How many OS kernels are going to be written in the next ten years? And how many business applications?

      How many written once and used once?

      Seems the question should be how many used, and how often used.

    18. Re:Um, it's online by NoMercy · · Score: 1

      I looked at that last one, and wondered, and decided not to take anyones word for granted wrote two very simple C++ programs two nested for() loops of 50k iterations and a tiny little sum at the end so it doesn't optimise the loops out of existance.

      3.450 seconds for the decrementing
      3.397 deconds for the incrementing

      the results were fairly consistant in both optimised and un-optimised programs (compiling with g++ and run on AMD XP)... I suspect it would be the other way around on the ARM processor, if there's no conditional code present inside the loops.

    19. Re:Um, it's online by dnoyeb · · Score: 2, Funny

      It does not matter. As I have said each time this stupid question comes up the whole thing is moot.

      Java VMs are written in C++ among other languages. This issue is just plain silly.

    20. Re:Um, it's online by Anonymous Coward · · Score: 3, Insightful

      Thank you! I am not the only one that noticed that these are not even equivilant code. Using sprintf when you expect speed is stupid. sprintf is for simplicity. Making 5 function calls in the middle of a for loop when once would have been fine is also stupid. Also Gxx type compilers are KNOWN to be slower. They are getting better. But the 3.3 branch is more of a staging for better things to come. I would be interested in the same thing done with the intel compiler. WITH all the sub libraries compiled with the intel compiler.

      Sure the code does the same thing. But the few code bits I looked at are not identical. To be a 'fair' test. All the functions need to be written in the same file. Then with *VERY* minimal changes work in both java and C. It wasn't even C++ code. Also if he used the G++ compiler? That is *KNOWN* to be very slow. They rewrote the sucker for 3.4. All the functions need to be called in the same way. All the loops need to be walked the same way. Etc...

      This test is bogus. I was willing to give the dude a listen. He even tries to defend what he does wrong. Its almost pathetic. For example he talks about GCC vs Visual studio. Then goes on to use G++. Interesting... Another good thing he does to 'obscure' the issues is to use overloads in C++ yet use method calls in Java. overloads are much slower. Usually firing off all sorts of copy constructors. Method calls are much faster. He even admits it C++ is faster in one case. Well that ONE case is about the only one where he has apples to apples. The rest are not. Also his 'method call' test is not the same thing. He did it in such a way that fires at least 2 copy constructors in the C++ way yet returns direct objects in the java way. C++ is slower in those cases. Well DUH.

      The idea that java or .net could catch up to C performance is interesting though. The code in these enviroents could be self tuning themselves. Did he prove that? I do not think so. NOT with that code.

      It is like I have always said. C/C++ does not produce awsome code. It lets you produce awsome code. But if your not carefull it lets you produce extreemly BAD code. It does not hold your hand. It has never claimed to. I could with a little bit of work (not as hard as some people would assume) produce the EXACT oposite results of what he got.

    21. Re:Um, it's online by ThosLives · · Score: 4, Insightful
      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.

      --
      "There are a dozen opinions on a matter until you know the truth. Then there is only one." - CS Lewis (paraprhase)
    22. Re:Um, it's online by GooberToo · · Score: 1

      Perhaps you can help me? I'm not a "java" guy, thoughI have previously played a little. He said that he compliled his java via, "javac objinst.java", which I did as, "javac objinst.java". I then compiled the cpp as, "g++ -O2 -march=i686 -o objinst objinst.cpp", which seems to match his. I then run, again according to the instructions, "time objinst 100000000", which seems to run fine. It runs to completion without error. When I attempt to run the java code, as, "time java -server -cp java objinst 100000000", I get, "Exception in thread "main" java.lang.NoClassDefFoundError: objinst". And yes, my java installation works fine. I use it with several java applications, including megamek and eclipse.

      Can anyon off a clue as to why the java benchmark doesn't work?

    23. Re:Um, it's online by dduck · · Score: 1
      for (int i=n; i>0; --i)
      ...for a small optimization.
    24. Re:Um, it's online by GooberToo · · Score: 1

      Doh! Right afterward I posted that, I figured it out. I had to change the, "-cp java", part to, "-cp .", and it works fine.

      In case anyone is curious, the results of the tests above, which was randomly picked, were measured as:
      cpp: 24.72user 0.04system 0:25.30elapsed 97%CPU
      java-server: 17.71user 0.59system 0:18.79elapsed 97%CPU
      java-client: 17.86user 0.66system 0:19.95elapsed 92%CPU

      Color me impressed. Now then, my system is not setup to do real benchmarking and I was running many other processes which may of stolen some CPU here and there. Just the same, the results do appear to match (this test anyways; it's the only one I ran so far). I also ran each result three times and they were all running very close each previous run, so, I'm willing to accept them for what they are -- reproduceable.

      I guess I'll have to spend some time thinking about what's going on and actually look at the code to make sure all is fair. Thus far, I am impressed.

    25. Re:Um, it's online by Anonymous Coward · · Score: 0

      itoa is not a standard C function though, which is why sprintf is used

    26. Re:Um, it's online by Anonymous Coward · · Score: 0

      Wrong. For basic data types i-- and --i are exactly the same (when not part of a larger expression). It's for instances of classes that i-- and --i are different, since i-- needs to create a copy to return.

    27. Re:Um, it's online by Anonymous Coward · · Score: 0

      otherwise any tool will suck.

      In Soviet Russia, do you suck tools?

    28. Re:Um, it's online by javax · · Score: 2, Funny

      bah, its obvious that Java is Turing complete, so you can do everything with it.

    29. Re:Um, it's online by Felinoid · · Score: 1

      Parent suggesting not using the Sun Microsystems HotJava web browser to view it "becouse it's slow".

      My responce:
      There was a really fast web browser once apon a time writen in perl.

      As a lot of people have noticed the "optomised C++" was really badly done vs the Java. There were mistakes made in both where the Java compiler could fix the mistake the C++ could not.

      Etc.

      As much the same here. The perl browser was a text browser. Very simplistic and made to demonstrate how perl can scoop up data from one website for use in annother. (Such as Slashboxes).
      HotJava is a full on browser but made entirely to demonstrate the power of Java. At the time it was originally created speed was not believed to be an issue. The browser reflects Java as it was much less than as it is (today). Where as IE and Netscape will take shortcuts and ignore features of HTML to make a fast reliable browser (I'm trying to keep a stright face) HotJava was made to show it can do the job and makes no such shortcuts leaning entirely on Java itself for reliability and blatently ignoring speed issues.

      I don't know how successful Sun was but I've never heard any complaints about it. (On the other hand I hear all kinds of complants about Lynx, MacOs and so on from people who've never actually touched same so this is a very bad rule of mesure)

      I'm reminded of a peace of code I wrote in Asmbly and someone else created code that was just as fast in C again in Pascal. Seams reasonable well optomised code in a simple application. Then someone did it in basic.
      The reason? In every version the application was idle about 90% of the time waiting for hardware. External facters made the code optomisation meaningless.

      --
      I don't actually exist.
    30. Re:Um, it's online by Anonymous Coward · · Score: 0

      I thought it was a test of Java against C++ not straight C?

    31. Re:Um, it's online by JPriest · · Score: 0

      Well, there is an interesting comment here the Java benchmarks do not factor in many things like loading and killing the clunky virtual machine. Sure it may not be fair to count slow VM performance when evaluating the application speed, but in any event the JVM still takes time and Java + JVM is still many times slower than compiled C++

      --
      Saying Java is nice because it works on all OS's is like saying that anal sex is nice because it works on all genders.
    32. Re:Um, it's online by Anonymous Coward · · Score: 0

      Well, it's quite brave to post any of your code to Slashdot, but posting it without compiling and testing it qualifies you as a "thrill-seeker".

      It's like going into a motorcyle bar and proclaiming in a loud voice that anybody who rides a motorcyle is gay.

    33. Re:Um, it's online by Anonymous Coward · · Score: 0

      As others have pointed out, you meant itoa( n, buf, 10 ), which runs about 3x as fast as sprintf(buf, "%d", i) in a head to head comparison, but the memory allocation and hashing code performance are going to swamp that difference, so you may only end up with a few % difference in switching. I'll leave the rant about not using unbounded string functions for another time.

      Regarding strdup: Unfortunately, the the strdup(or some equivalent) is necessary because the hash used only stores a pointer (note the use of hash_map<const char*, int, hash<const char*>, eqstr>). However, the benchmark writer forgot to free the memory. oops.

    34. Re:Um, it's online by dduck · · Score: 1
      OK, I thought that the use of --x and ++x was recommended in loops for all types. To think that I have spent so much time re-hacking my brain for that variation of the canonical
      for
      loop... :)
    35. Re:Um, it's online by Badassmofo · · Score: 1

      "overloads are much slower. Usually firing off all sorts of copy constructors."

      Curious, what exactly do you mean by this statement?

    36. Re:Um, it's online by Pointer80 · · Score: 3, Informative

      Read the article. He said that he included JVM startup time in the benchmarks.

      /pointer

      --
      [%- PROCESS life -%]
    37. Re:Um, it's online by Anonymous Coward · · Score: 0

      Then I call bullshit. 300 benchmarks prove java is slow, and 1 guy fakes some numbers and expects people to accept his findings as fact? I will believe these numbers when they are verified by several other sources, I am sure somone will post a rebutal.

    38. Re:Um, it's online by cheesybagel · · Score: 1

      The point was strdup() (which does a malloc() followed by a memcpy()) is not necessary in that function call.

    39. Re:Um, it's online by cheesybagel · · Score: 1

      Hey, this is Slashdot and I'm presently booted in Uncle Bill's hell OS. ;-)

    40. Re:Um, it's online by cheesybagel · · Score: 1

      The first strdup() for the hash creation is necessary. The second strdup() for the hash lookup is utterly useless and a memory leak.

    41. Re:Um, it's online by GooberToo · · Score: 5, Informative

      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.

    42. Re:Um, it's online by Halfbaked+Plan · · Score: 1

      A 68HC05, 68HC11, the Zilog Z8's, the PICs. Nope, they're not IBM 650's.

      Umm, Knuth makes heavy use of a 'virtual machine' in his texts, by the way.

      --
      resigned
    43. Re:Um, it's online by jallen02 · · Score: 1

      Intelligent usage of the System.gc() method can result in collection and cleanup that results in optimal usage.

      However it is not really valid to say that calling System.gc() is the same as deleting ONE indiviudal object in C++. Calling System.gc() has a lot of overhead that the garbage collector can better deal with. Direct client calling of the garbage collector is not a good method of testing performance. Better to pass in some parameters to the Java VM telling it the max heap size allowed and it will constarin itself to that memory limit. Much better than just calling System.gc() and saying its the same as calling delete in C++.

      Jeremy

    44. Re:Um, it's online by Alan+Shutko · · Score: 4, Informative

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

    45. Re:Um, it's online by Doctor+Faustus · · Score: 1

      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

      Or basically, Java is faster if you tend to do stupid things in your programs, like use recursion for a Fibonnaci sequence.

    46. Re:Um, it's online by jmccay · · Score: 1

      I would like someone to rewrite this C++ code to fix all these problems with the code to compare apples to apples. Then we could have better numbers, and a better comparison.
      Joe M.

      --
      At the next eco-hypocrisy-meeting, count the private jets used to get to the meeting. Should be interesting to see that
    47. Re:Um, it's online by Trepalium · · Score: 2, Interesting
      Not only that, but the 'fast path' in these otherwise identical functions is completely different. It means the C code may or may not be following more JMPs to get to the more common case. I have not read the code, but I would imagine the Java runtime could detect the more common path and optimize for it, but the C code is fixed in one direction. Maybe it optimizes it for C++, maybe it penalizes C++. Without taking a good look at the source, I can not say.

      Now, the other question is why use the ? operator at all? It's no faster than an if statement in a case like this. This code fragment would be much easier to read, for example:

      if (m == 0)
      return (n + 1);
      else if (n == 0)
      return Ack(m - 1, 1);
      else
      return Ack(m-1, Ack(m, n-1));

      (Please imagine it's indented properly because slashdot's ecode likes to strip spaces)

      The other benefit to this code is it should be clear to even the worst optimizer what it can optimize and what it can't.

      --
      I used up all my sick days, so I'm calling in dead.
    48. Re:Um, it's online by GooberToo · · Score: 2, Insightful

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

      That's simply not true if you expect benchmarks to reflect real world applications. Sure, it might be true for trivial utilities but for applications that stay alive for long periods of time chugging along, which is probably the majority of the worlds useful applications, it makes the results invalid. Or, at a minimum, sets greatly unrealistic expectations.

      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.

      This is true..."on some workloads". I certainly recognize that fact. I hoped I had more or less pointed that out in my original message. At any rate, for real world workloads, I would offer that such expectations are not realistic.

      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.

      Well, technically, even with the 1:1 implementation, it's not forcing collection. It's actually hinting to the GC system, that it should consider doing so. The GC is 100% free to ignore such a request. This is per the java specifications. Which, makes plenty of sense because doing so tends to greatly increase the window where GC can improve performance in various workloads. The problem is, I honestly don't know where implementation and specification lay. 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. ;)

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

      Yes, I'm aware that there are no leaks. That's not my complaint. My complaint is that just about every java benchmark I've ever seen is so artificially small that they all appear to purposely avoid GC ever becoming part of the benchmark. Since most major applications simple don't start, run for 20 seconds and exit, I don't consider the presumed bevaior to be valid.

      The secondary point I was attempting to raise (along with awareness to the hidden gc issue) is that once Java is forced to start collecting, it's pays a significant cost. A cost, I'd hazzard a guess, that brings about the common complaints of Java. And that, I offer, is the difference between labratory tests and real world application. ;)

    49. Re:Um, it's online by GooberToo · · Score: 1

      However it is not really valid to say that calling System.gc() is the same as deleting ONE indiviudal object in C++.

      Why not? According to the java docs, it's a hint that the GC should considering gc'ing some time soon. Technically, the majority of the time, according to java's docs, it should do nothing at all. So, if the majority of the calls are more or less an empty function call, what's the harm in doing it? Well, other than making the java application pay for it's allocation costs.

      Has the JVM changed such that it no longer hints? Are you saying that it now actually forces collection to occur?

    50. Re:Um, it's online by Anonymous Coward · · Score: 0

      There is no itoa function.

    51. Re:Um, it's online by Trepalium · · Score: 3, Insightful
      That's not a bug in the tests, it's a feature.

      It's neither a bug, nor is a feature. It's a difference, and possibly a testing methodology flaw.

      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.

      And on certain workloads it can decrease performance. Coders that know their languages should recognise the difference between the two memory allocation methods, and adjust their code accordingly. I seriously doubt you'd claim that java's garbage collector is always faster than manual memory management.

      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.

      Perhaps, but it's also unfair to have a 'benchmark' that always pays the penalty of C++ memory allocation and deallocation, but never pays the penalty of Java memory allocation and deallocation.

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

      Just because the memory is freed back to the system after termination doesn't mean it isn't a memory leak. It's a bad practice to allocation memory and not free it when you're writing C or C++ code. A longer running process would probably be more fair, or even a garbage collect at the end of execution. After all, on 'real' programs, a garbage collection is quite likely.

      --
      I used up all my sick days, so I'm calling in dead.
    52. Re:Um, it's online by Anonymous Coward · · Score: 0

      "Needs to" is a very strong statement. Last I checked, C++ still allows the as-if rule. It's not impossible to imagine a C++ compiler having justification to turn i-- into --i.

    53. Re:Um, it's online by maxwell+demon · · Score: 1

      One could "emulate" the Java GC in the C++ benchmarks by replacing operator new/operator delete with the following scheme:

      * operator delete just adds the pointer to a pending delete list
      * operator new checks some condition (like the amount of free memory), and if it decides that "collecting" is necessary, it actually frees the pointers on the pending delete list, before allocating new memory

      I think this behaviour (which does completely conform to the letter of the C++ standard) would make C++ memory management times more comparable to Java.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    54. Re:Um, it's online by Anonymous Coward · · Score: 0

      Depends on what bar you are walking into doesn't it?

    55. Re:Um, it's online by sammck · · Score: 1

      Or at least until someone makes a fast Java written in something besides C/C++, I wouldn't look for C/C++ to be replaced :-).

      --
      sjm
    56. Re:Um, it's online by ipfwadm · · Score: 4, Interesting

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

    57. Re:Um, it's online by starbirdman · · Score: 1

      From what I recall reading a while back, calling garbage collection is explicitly discouraged. Even if this is just a hint, the more often it is called the more likely the garbage collector is to run. Since running the garbage collector IS very expensive you want to reduce the frequency with which you need to call it, not increase the frequency.

      If you are really conerned that the test will end before the GC has been called then make the test longer. These two systems are designed to be used differently, trying to cast one as another is going to just lead to bad results. Besides, from what I've read and my experience working in C#, GC happens fairly often, the test probably doesn't even need to be that long in order to hit GC at least once.

      We have a little windows forms app written in C# that plays around with images. At startup it recurses through a large directory structure and builds several ArrayLists, the largest of about 3000 objects.

      During this short time, about 0.61s of processor time, it performs 5 gen0, 3 gen1, and 3 gen2 garbage collections. There is just short of 4 megs in all of the heaps at the end.

      Now these are rough numbers about one (maybe a bit poorly written) little app, but I was hoping to give an idea that GC is occuring a lot even without you forcing it to, and that it is not necessarily the albatross that it is sometimes made out to be.

      As for Garbage Collection being good for some workloads but not for others, I echo everyone else in agreeing, make the benchmark an actual workload, not a contrived function. I think GC is a great idea that a good implementation of which could lead to increased performance in a lot of situations. However, good benchmarks showing how the current generation of garbage collectors are performing are not easy to perform, and so are few and far between.

    58. Re:Um, it's online by Anonymous Coward · · Score: 0

      Nah... in Soviet Russia, the tools suck you.

      You must be new to Slashdot ;o). Welcome.

    59. Re:Um, it's online by jovlinger · · Score: 4, Insightful

      "Any sufficiently complicated C or Fortran program contains an ad hoc informally-specified bug-ridden slow implementation of half of Common Lisp." -- Philip Greenspun

      / took way too long to google

    60. Re:Um, it's online by Tony-A · · Score: 1

      It's neither a bug, nor is a feature. It's a difference, and possibly a testing methodology flaw.

      Seems like benchmarks always have problems. Even using them for diagnostic purposes, they are capable of outright lying. Apples and oranges is probably closer than most benchmarks manage. If you have an agenda it's almost trivial to rig benchmarks to fit that agenda.

      Which is faster, a well-tuned Ferarri or an old water buffalo?
      Put 'em in a rice paddy and find out.
      (If it's a very long distance, wait for the rice paddy to dry out and still be faster;)

      Which is faster at moving sand, a wheelbarrow or an 85-ton truck?
      How much sand?

      Strategies for memory allocation:
      Fixed preallocated memory. Never leaks and never runs out.
      Allocate as needed. All freed at the end.
      Allocate as needed. Garbage collect as needed.
      Allocate as needed. Explicit freed when not needed.

      Depending on circumstances, any of the above could seriously dominate all the others.

    61. Re:Um, it's online by Anonymous Coward · · Score: 0

      I looked at the Ackermann and Fibonacci implementations. If you used better algorithms for these computations you could beat both the C++ and Java versions he has using just about any implementation language you chose.
      Both algorithms are practically textbook examples of how a runtime optimizer can beat compile time only optimization of the same algorithm. In both of these situations you compute the exact same value over and over a ridiculous number of times. If you switch to more intelligent algorithms there becomes less runtime optimization opportunities and you have to rely on the optimization of your compiler. Furthermore, you get overhead from the runtime system which will hurt your performance.
      I did a brief test of just the computation of Fibonacci(45). Java with -server took 21 seconds, GCC 3.5.0 built from CVS head today with good optimization switches took 15 seconds. Using a better algorithm and implementing in Python, the computation took 0.031 seconds(Hello World in Python took 0.029 seconds).

    62. Re:Um, it's online by gsasha · · Score: 1

      Are you blind guys?
      strdup() performs memory allocation. WITHOUT FREEING!!! It's just a memory leak, no wonder that performance sucks.
      If he managed to run the benchmark long enough to hit swapping, then the performance would sink so low that C would be slower than that of an abacus!

    63. Re:Um, it's online by Anonymous Coward · · Score: 0

      I think you should be able to do something like this using the pool allocator from recent GCC versions or from Boost.

    64. Re:Um, it's online by Kouzdra · · Score: 1
      All tests from this benchmark has been designed for working with arrays of Java primitive types. On such tests JVM optimizer does very good job. But Java is really terrible language, if you need to optimize data representation.

      Java performance vs C++ (preferrably with Boehm GC) looks very bad in working with large complex data structures. Probably even on standard sets C++ will be better than Java. If data representation was tuned for speific application needs, gap between C++ and C++ should increase.

    65. Re:Um, it's online by JohnFluxx · · Score: 1

      Just because it has no effect, doesn't mean it takes no time to run.

    66. Re:Um, it's online by Sinterklaas · · Score: 2, Informative

      Technically, the majority of the time, according to java's docs, it should do nothing at all.

      It doesn't say that at all:

      "Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects."

      So, if the majority of the calls are more or less an empty function call, what's the harm in doing it?

      The VM can't determine whether a gc is useful or not without a full heap scan. AFAIK, calling System.gc() will usually result in a full scan, totally defeating the standard gc'ing (which is supposed to be efficient as is). You aren't supposed to call System.gc() except in special circumstances.

    67. Re:Um, it's online by Sinterklaas · · Score: 2, Insightful

      Calling System.gc() will usually result in a collection. The VM can't know whether a garbage collect will be useful, because only a full mark and sweep will reveal that. Thus, while the docs state that garbage collection will not necessarily happen after a call to System.gc(), all current VMs will do a full gc (AFAIK). That makes sense because the programmer can determine the need better than the VM.

      The JVM is designed to make most efficient use of the available RAM and calling System.gc() totally defeats that. To 'forbid' Java from doing it's thing is as fair as disallowing the C++ from using pointers, non-objects (except primitives) and other features which can't be found in Java. Obviously, that is wrong because those features make C++ what it is, just like (unforced) gc is an inherent part of Java.

      The only way to determine what the effects are of garbage collection vs (de)allocation is to design a benchmark specifically for this purpose. For instance, you could handle some big images and see how fast each language can complete the benchmark. Another interesting benchmark is to handle a large amount of small objects. However, in the end, the effect of garbage collection on real world apps can differ greatly, depending on:
      - the total amount of memory the app can use
      - the number of allocated objects
      - the size of objects
      - the lifetime of objects (Java is far more efficient with short-lived objects, for which it uses a mini-heap and mini-gc)
      - the workload of the app (can it do garbage collection during a time of low load?)

      The results can differ greatly depending on the particular situation that you are looking at. Of course, it is true in general that it is rare for a language to be better on all fronts, so you always need to look at what you want to do and how well the language is suited to do that. That is also the reason why I hate broad generalizations like:

      Sadly, I'm once again seriously disappointed in Java.

      Just because the benchmark is flawed, doesn't mean that Java was somehow bad. Especially since your benchmark was a thousand times more flawed. Since you have shown little knowledge about Java (every beginning Java programmer learns that you should avoid calling gc directly), I suggest you stop making these stupid comments. /end rant

    68. Re:Um, it's online by Anonymous Coward · · Score: 1, Insightful

      Garbage collection has long be heralded as a faster solution than explicit new/delete handling of memory allocation. Adding System.gc() is dumb. Escape analysis in the JVM means explicit deletes are placed in where an object clearly doesn't escape a particular level of Java's scope. You can improve GC and escape analysis by assigning object references the value of null.

    69. Re:Um, it's online by sploxx · · Score: 2, Interesting

      Heh, it's funny, just yesterday, Bjarne Stroustrup himself gave a lecture at our university!

      He spoke *a lot* about 'efficiency', and IMHO, he did have a valid point. He compared C++ to C and FORTRAN and made good arguments why C/Fortran is slower than highly optimized C++ code nowadays (Because of the amount of information a C++ compiler can collect about the program's structure... in C everything is flattened to a low level by the programmer already and information is lost for the compiler).

      Asked after his lecture if there are plans for a virtual machine for C++ (as an *alternative* to native code), Mr. Stroustrup strongly denied that. I think this is one of the more important reasons why Java is considered 'better' by many people. Because it *seems* that, with the VM, it's more portable. There is clearly not engineering reason for a C++ VM, but politically, it would give C++ the opportunity to gain ground against Java.

      You have to, of course, use appropiate C++ paradigms, like templates emulating lazy evaluation etc. A "naive" matrix class in C++ is nice to write, but not very efficient to use.

      Even if you cry out loud that efficiency doesn't matter any more, it's, at least somewhat, wrong. It's an arrogance of the programmers against the users of their programs. If one programmer saves 10 hours of time but for each user, using the program takes 10min longer (be it startup times or whatever), it's time-inefficient if only 100 people are using the program. And you have to take into account that the time of the users adds up more easily than that of the programmers. They're probably not running the program once, but multiple times...

      Of course, java has it's uses, e.g. client-side interfaces running in the browser.

      But the argument, stated over and over again, that Java is/can be faster because of runtime optimizations, is *really* flawed and just ignoring facts. There are compilers which can do optimizations on profiling data from the actual running program. Beat that java. A compiler tailored to the machine *and* the beloved runtime optimizations.

    70. Re:Um, it's online by supersnail · · Score: 1
      How many OS kernals are going to be written in C++ for that matter.

      Most os the OSes I work with are written is assembler or vanila C.

      C++ is not a good language to write an OS in (or anything else for that matter :-)

      --
      Old COBOL programmers never die. They just code in C.
    71. Re:Um, it's online by Anonymous Coward · · Score: 0
      As typically observed, I'm seeing the benchmarks take serious advantage of java's GC mechanism, whereby, they never pay the piper.

      Shocking! Program takes advantage of language features! How dare they!

      Sadly, I'm once again seriously disappointed in java.

      Sadly, there are people who want to be disappointed in various technologies, and promote competing technologies and companies.

    72. Re:Um, it's online by Alexis+de+Torquemada · · Score: 1
      If you want, you can read the actual author's piece instead of a news story about it

      Plus, this page won't reload itself every 10 seconds.

      $ echo 192.168.254.254 www.sys-con.com >>/etc/hosts
    73. Re:Um, it's online by schabi · · Score: 1
      but until one can write an OS kernel in it

      One can actually write OS kernels with java, see e. G. http://www.plurix.de/ or http://www.jxos.org/.

      --
      plim-plam-plompudding
    74. Re:Um, it's online by spiko-carpediem · · Score: 0, Offtopic

      Sadly, I'm once again seriously disappointed in java.
      Bah. In Russia Java is disappointed by you!

    75. Re:Um, it's online by nikster · · Score: 2, Insightful
      I'm seeing the benchmarks take serious advantage of java's GC mechanism
      the first part of your analysis is sound: the benchmarks are highly questionable since the Java code never runs the gc, thereby cheating it's way out of having to do mem management.
      very good point.
      Worse, when I ran it with a 1:1 ratio of delete:System.gc(),
      so, you took it back to Java, and biased the test in favor of C++ by running way too many gc's, which, as you point out don't even mean anything because the gc doesn't get invoked immediately. by adding System.gc() to the Java side of the test, you in fact added some kind of randomizer to the code. you don't know what System.gc() does - it's a notification that the gc may run, yes. But you don't know what exactly the system will do after it's called. For all you know, it could stall for a couple of seconds. Or it could count all objects in memory. Or... anything. You added a random delay to the Java side of things.
      and, lo and behold, you "proved" that c++ is faster. now, if the original comparison was biased, this was surely worse.

      a better test would probably be to let the c++ side never collect anything. and to stop the watch before java starts collecting (just use a huge max. heap size and set it to use the traditional gc and it won't collect anything for a while).

      Regarding the article: It's kind of silly to count the JVM startup delay in the tests. Because for some things it will matter, e.g. programs that get run, then shut down again zillions of times. That's why you can't write command line tools in Java. For other things it won't matter at all because they get started once and then continue running (client-GUI software, server app). Also, new JVMs from Apple (and Sun, in the future) just won't have the startup delay because they will statically link precompiled versions of the java class library (rt.jar).

      IMHO, speed matters only in one area: When doing calculations in tight loops. There, i believe Java is just as good as c++ because the hotspot compiler actually works and will generate fast, optimized assembler code out of the java loop.

      I did some unrelated speed tests within Java (checking the overhead of final method calls - it turned out to be zero as it gets optimized away) and found out, to my surprise, that a simple calculation in a for-loop ran at 400 million loop iterations per second, or 1/3 of phyiscal machine speed (1.3GHz Pentium-M). I found that impressive. Come to think of it, it was probably exactly the DRAM access speed (i was accessing a huge array).
    76. Re:Um, it's online by Haeleth · · Score: 1
      (Please imagine it's indented properly because slashdot's ecode likes to strip spaces)

      I see this almost every day, and I really don't understand why people make this claim. Look - here's your example, using ecode tags, and indented properly:
      if (m == 0)
      return (n + 1);
      else if (n == 0)
      return Ack(m - 1, 1);
      else
      return Ack(m-1, Ack(m, n-1));
      What magic did I use to achieve that result? Why, I put two spaces at the start of each line that I wanted indented, just like you'd expect. It's hardly rocket science.
    77. Re:Um, it's online by KowShak · · Score: 0

      What can be done in Java that can't in C++?

      The sole advantage of Java was "write once run anywhere" and with platform independant C++ you can get close to that anyway by recompiling.

    78. Re:Um, it's online by Xugumad · · Score: 1

      Here's the thing - I'd never write code like that. I'd write pooling code to handle the objects instead. Which would take longer to write, yes, but probably less time to run, and certainly a lot less than allocating and de-allocating objects continuously.

    79. Re:Um, it's online by Anonymous Coward · · Score: 0

      This page details some techniques (in the 'D' programming language) for overcoming the problems of the garbage collector. Some of them can be replicated in java.

      http://www.digitalmars.com/d/memory.html

    80. Re:Um, it's online by Anonymous Coward · · Score: 1, Interesting

      Out of interest did you change your jvm.cfg file to run the server JVM by default, or run it from the command line such as java -server, as this results in much greater than 2 times speed increase in most cases.
      It suprised me that this was not the default and yes the startup time is slower but it is dramatically faster when running.

    81. Re:Um, it's online by basingwerk · · Score: 1

      That type of programming is not as big a part of the sector as it once was. I assume it's some kind of engineering number crunching. I'd expect C(++) to do very well if you lay out the rows, columns and loops properly and optimise it to prefetch the data into cache memory and parallelise the instructions across the chip pipelines. Fortran might do better even. Java does not strike me as the best kind of language for that type of work. If you use objects, the memory access could be jumbled and prefetch/pipelining might not be effective. If, however, you use arrays of primitive data types in Java, maybe the prefetch performance could be OK, but I wonder whether Java could arrange instruction pipelining?

      --
      I stole this .sig
    82. Re:Um, it's online by gbjbaanb · · Score: 1

      WRT your comment whether java or .net could catch up to C performance....

      this isn't 100% relevant, but does give some interesting insights into how C++ and .NET performance works - and .net is just like Java, remember.

      Some guys took the Quake2 source code, compiled it up using VC++7, then they converted it (with as little modification as possible) to compile in managed c++. They did it to show how easy it was to convert all your legacy apps to shiny new .net apps, but a side-effect is that they created an apples to apples benchmark (well, that's as non apple-to-orange as anyone's going to get).

      The .net one performed at 85% of the performance of the native one.

      Now, I know its not exactly a business app, but it does show a real world application with no differences besides those mandated by the platform.

      I just found it interesting... read it here

    83. Re:Um, it's online by breadbot · · Score: 1
      ...There are compilers which can do optimizations on profiling data from the actual running program. Beat that java....

      I don't want to be partisan here, but that's exactly what Sun's Hotspot JVM does (note: article from 1998 -- first hit on Google hotspot optimizations).

      The Sun JVM analyzes run-time profiling data in real time as the code executes and optimizes the "hot spots". In practice, you can even see it -- if you run a loop many times, the first few times after the JVM starts it will usually run slowly, and then it will speed up as the hot spot compiling kicks in.

    84. Re:Um, it's online by cookd · · Score: 2, Interesting

      Most of what you said is very true. But things went downhill in the last two paragraphs.

      Efficiency matters, but sometimes it doesn't come in the obvious ways. To set the tone, here are a few examples.

      The Bubble sort takes only a few lines of code and has no significant memory requirements. A QuickSort takes 50 to 100 lines of code and uses a recursive algorithm requiring a stack of some sort. Yet for some reason many applications choose the QuickSort.

      Virtual memory imposes a huge performance penalty on the system. Every memory access has to be translated into the physical address. Page tables take up a significant percentage of RAM. They complicate systems programming significantly. And somehow we would never dream of designing a serious system without virtual memory. And even after adding a FOURTH level of page tables, somehow the AMD64 is able to outperform the two and three level 32 bit chips.

      Running software at different privilege levels introduces a huge penalty of context switching. An OS call, which cost only 4 to 10 cycles under DOS, now costs 1000 to 3000 cycles under a "modern" OS. Why would we actually prefer such gross inefficiencies?

      Instead of setting up a direct cable link for data transmission across the US, which would create a direct link of only 3000 miles, many industries find it more efficient to sent the data 52,000 miles into space to have it bounced back by satellite.

      The fastest way to get a missile from here to Russia is also via a trip into space.

      What I'm trying to get at is that there are a lot of cases where the best solution looks wasteful until you get the big picture. You and I understand how a 4 level system of page table lookup can end up outperforming even a direct memory access scheme for some tasks, how kernel/user mode is a significant and necessary part of modern programming, even at the huge cost it adds to system calls, and how going the "long way" can be faster than the more direct route. So don't be afraid to consider alternatives that don't appeal to you at first glance.

      So you don't like Java and other inefficient VM-based systems, and you don't believe that it can be faster? Yes, there are many systems for analyzing runtime behavior and using that data to perform static optimizations. But there's no reason Java can't apply those same optimizations. On the other hand, there are optimizations that Java can do that you CAN'T do with static code. For example, Java can inline a function across a shared-library boundary (this is a HUGE win). Java can remove expensive security access checks for an application that is already running at full trust level. Java can optimize the generated code for the current processor - Pentium 1 through 10? SIMD? Super-SIMD? MMX or no? Floating point? All of these cases can be handled really well by Java, and it can pick the instruction mix that matches your system perfectly. The static code generator has to make some compromises. You can load a different DLL for each processor, but honestly you can only distribute so many flavors of your library... and they'll be obsolete the next time Intel decides to change its optimization strategy. Running on a single proc system? You can seriously simplify your synchronization primitives, saving a LOT of cycles on multithreaded code. Lots of memory? Java can trade space for speed. Tight on memory? Java can trade speed for space. And it can change its mind from day to day, depending on what other apps you have running. The list goes on and on. Not all of the above optimizations have been implemented in production JVMs yet, but they have all been researched, and they aren't theoretical -- there are real performance tests that show they can make a difference. They just need a few more years to be built into the next generation of VMs.

      A few other areas that people often don't think about: Bytecode is usually significantly more compact than the resulting machine code, especially on RISC chips. Throw in

      --
      Time flies like an arrow. Fruit flies like a banana.
    85. Re:Um, it's online by sploxx · · Score: 1

      First of all: You can't win (or have already won) an argumenst over VMs. This would be not C++Java but C++VM. Silly comparison, take a C++->JVM compiler!
      Now, a bit more detailed:

      [Bubblesort/Quicksort-Comparison]
      Do you think, that, in C++, a quicksort() is impossible or needs serious brain-twisting? It's as easy as in Java...
      As we all know, BS is O(n^2) and QS is O(n log n) in the average case... but this is simply no argument.

      [Efficiency and the big picture]
      Here you're somehow assuming that you have to stay on a lower level with C++ than with Java. Know what? Want to get really high-level? Do not choose C++/Java, use Lisp(Scheme) or Haskell.

      [Other JVM specific anti C++-rants]
      See above. That's the JVM, not the language. Although all your arguments for JVMs are (theoretically) true, I have yet to see a JVM implementation that outperforms C++. One of the reason why C++ still gets compiled to native code, I think.
      Please don't get me into an argument here why the JVM is IMHO not very well designed for perfomance.

      [Memory management]
      Garbage collection is available by using external libraries in C++. A VM implementation would certainly contain such a garbage collection library.

      And no, if you do write C++ and _NOT C_, you'd hide all of the memory management stuff in proper classes. (The idea of "resource initization == resource allocation")

      [Design level of Java]
      Sorry, but if you think of C++ only as a 'better C', you really don't know C++. C++ plays easily on the same level as Java.

    86. Re:Um, it's online by Anonymous Coward · · Score: 0

      You're right, it is an apples and oranges comparison in some sense of the phrase -- Java is different than C++, I'm glad you are here to point out these observations. Java uses garbage collection while C++ is programmer managed memory.

      First of all, if you'd like the benchmark to be "fairer", making Java like C++ is not the answer. Instead, why not try not deleting any of the objects created in the C++ benchmark code. If you're so worried about C++'s delete operator just taking tons of time -- don't use it. This is after all only a benchmark, and who cares about perfect memory usage. If you think Java never ends up garbage collecting during these benchmarks, then don't use the delete operator. System.gc() spawns the entire garbage collection process, and quite frankly, should never be called. The entire purpose of garbage collection is having the VM do it for you, and optimize it where necessary. To block the entire thread of execution to let the garbage collector run all its checks is just insanity, and is be no means an apples to apples comparison, it's just plain stupid.

      The entire point of the benchmark was merely to say that Java is not as slow as it used to be, and in fact, research on garbage collection techniques have improved a lot. Why do you think Microsoft is moving all of its new APIs in longhorn to "managed code"? Garbage collection is the future of client applications. It started on the server, and now is heading to the client. Try C# with Mono or VS.NET. It's fast, and far worth the added developer productivity, and more importantly, produces far more robust applications. So rather than trying to change these new garbage collection langugaes in benchmarks, which are fairly useless anyway, try to appreciate the larger picture.

    87. Re:Um, it's online by khrtt · · Score: 1

      Put a breakpoint in the copy constructor and you'll find out:-)

    88. Re:Um, it's online by Anonymous Coward · · Score: 0

      "Any sufficiently complicated C or Fortran program contains an ad hoc informally-specified bug-ridden slow implementation of half of Common Lisp." -- Philip Greenspun


      "The trouble is, so does Common Lisp" -- Me
    89. Re:Um, it's online by netstat · · Score: 2, Insightful

      The garbage collector runs in a low priority thread. If you just run some code that is doing nothing but calling System.gc(), then of course it will be called. However, if your code is actually trying to do something else, it really is just a "hint" as the other poster stated.

    90. Re:Um, it's online by GooberToo · · Score: 1

      I completely agree with you. Your assessment matches my own, which I've offered in other threads. It's just that making the changes in the java code was the fastest path to gleen some measure of comparability. I completely agree that my changes were completely lacking scientific method but they were 100% reproducible, which does seem to lend some credence to them (with a large grain of salt).

      As for JVM start up, I think it's completely fair and just to add it in. For short run utilities, it reflects real world delays. For long run applications, it will become noise. As such, in either case, it's realistic and completely fair.

      There is no doubt that hot spot can certainly make note worthy improvements. Heck, python's own pysco seems to offer additional proof of concept. Just the same, clearly these benchmarks are quickly proving that they do not reflect real world applications in the least.

      FYI, I attempted to let the 1:1 implementation run all night. It never completed. I had to kill it this morning. So clearly, more is going on under the covered with System.gc() than is typically known (at least be me). So, I think it does support the argument that a 1:1 implementation is clearly not an apples to apples comparison either.

    91. Re:Um, it's online by angel'o'sphere · · Score: 1


      Well, technically, even with the 1:1 implementation, it's not forcing collection. It's actually hinting to the GC system, that it should consider doing so. The GC is 100% free to ignore such a request. This is per the java specifications. Which, makes plenty of sense because doing so tends to greatly increase the window where GC can improve performance in various workloads. The problem is, I honestly don't know where implementation and specification lay. 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. ;)


      I do not understand what youo mean with that. There is no way for a Java Programmer to interfer with the GC except for calling System.gc().

      System.gc() starts the garbage collector, its not a hint. Other "hints" do not exist. Its not necessary to say ref = null, as a hint. That only costs CPU time and has no effect.

      angel'o'sphere

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    92. Re:Um, it's online by GooberToo · · Score: 1

      This is true...but c++'s delete isn't exactly free either. ;)

    93. Re:Um, it's online by angel'o'sphere · · Score: 1


      I think this [...] would make C++ memory management times more comparable to Java.


      I dont think so.

      You want to compare a GCed Java program with a C++ program having manual memory allocation and deallocation. You don't want to have a fake GC in the C++ program to modivy its runtime behaviour.

      The right GC for your appplications runtime behaviour is as fast as the perfect manual allocation or deallocation and in most cases even faster.

      The only point is: 99% of all applications with manual memory management are far from having the "perfect" allocating/deallocating schema. (Read Bertram Meyer and his researches regardin C versus Eiffel and gc)

      angel'o'sphere

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    94. Re:Um, it's online by GooberToo · · Score: 2, Interesting

      It doesn't say that at all

      I wish I could find what I originally read. It stated that it simply issued a request for the gc to collect. Under a high load (tight loop, in this case), chances are, the gc will not collect. Accordingly, I have no problem finding many posts by "java gurus" which seem to be under the same impression I am (that clearly doesn't make it true though). Also, even here, others have piped in and offered that gc is run in a low priority thread whereby, the "hint" is actually a mechanism which attempts to wake up the gc, assuming it's not already running. Thusly, while I do agree that calling System.gc() on a one to one basis is not fair (clearly not an apples to apples comparison), I'm still not convinced that simply calling System.gc(), and it returning, means that all memory has been collected.

      Regardless, I do believe I have a legitimate point and that these benchmarks are fundimentally flawed.

    95. Re:Um, it's online by GooberToo · · Score: 1

      Just because the benchmark is flawed, doesn't mean that Java was somehow bad.

      I didn't assert that Java was bad. Personal disappointment is certainly my right.

      Especially since your benchmark was a thousand times more flawed. Since you have shown little knowledge about Java (every beginning Java programmer learns that you should avoid calling gc directly), I suggest you stop making these stupid comments. /end rant

      Actually, my "benchmark" was not flawed at all. It did exactly what it was supposed to do. If you took it at face value, then that's your problem and not a fault of my results. What my result attempted to prove was that these benchmarks were flawed and that they were purposely hiding java's gc overhead. What my "benchmark" also showed is that java's gc overhead can be significant. It also highlighted the fact that since c++'s new and delete operators can be overloaded, a fair comparison would be to make the c++ implementation perform the same collection deferment.

      I think results did exactly what I setup out to do. Take them with a grain of salt but walk away with the lessons learned.

    96. Re:Um, it's online by Surt · · Score: 1

      Be sure to have a look at memory deallocation, as discussed in another post.

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    97. Re:Um, it's online by GooberToo · · Score: 1

      This is what I've "learned", but I have idea as the the validity of it. It does seem to jive with everything else I've heard and read, so I don't currently have reason to question it.

      It appears that we're both right! What? Ya, it appears that System.gc() does not immediately cause the collector to run, well, not always and not in the same thread of execution. Furthermore, it's also considered a hint because if you call it and the collector is already running, it supposed to ignore the additional requests. Lastly, it appears that the collector runs as its own, very low priority thread. That means, it probably won't get much runtime on systems under heavy loads. Especially when the code in question is a tight loop.

      So, I do agree that a 1:1 implementation is not fair, just the same, it is technically a hint or request to collect, nothing more. Furthermore, the completion of System.gc() does not appear to actually indicate that collection is anywhere near completion.

    98. Re:Um, it's online by GooberToo · · Score: 1

      Thanks! Chances are, I'm right in the middle of those other posts. ;)

      Cheers!

    99. Re:Um, it's online by Gverig · · Score: 1

      A lot of people replied to your post, but I want to add a point I did not find in replies (maybe I missed it).
      I feel that there are two primary objectives any language comparison tests; one is to test optimizations done by compiler/JVM and two is to compare "normal programming style" from both languages.
      I do agreee with you that tests are not fare from the first stand point, as C++ test incurs overhead of destroying objects. However, isn't this standard programming style for C++? How often have you built resource managers and how often have you used them for small objects, like strings?
      The more fare test would be to have the test run out of memory and do a gc ONCE (well, or few times for statistics). In THAT case you would have code running in conditions as close to "wild life" as possible.
      I like java very much and I am very glad to see that these days it is being compared to C++ and people ARGUE about which one is faster. Just few years ago the argument would be about "hey, performance is not what Java is all about!"

    100. Re:Um, it's online by Trepalium · · Score: 1
      Doesn't work for me with Firefox.
      0 spaces
      1 space
      2 spaces
      --
      I used up all my sick days, so I'm calling in dead.
    101. Re:Um, it's online by SumoRoach · · Score: 1

      Agreed. It doesn't seem to have a call give the VM a hint to do garbage collection. Shouldn't that be what it's doing by itself? I would assume that System.gc() means, "Hey VM, I know you're supposed to do this when you have some free time, that ain't happening anytime soon, so drop what you're doing and do it now."

    102. Re:Um, it's online by GooberToo · · Score: 1

      Well, as I understand it, it's supposed to collect as time allows AND when it's triggered predefined thresholds, as derived from things like maximum allowed memory and current free heap, etc., etc. I'm sure I'm over simplifying, but I think the point stands.

      Beyond that, an explicit call to System.gc(), means, if you are not already doing so, please start attempting to collect. The collector then runs in a low priority thread, which was kicked off by the System.gc() call, again, assuming it's not already running.

    103. Re:Um, it's online by GooberToo · · Score: 1

      Garbage collection has long be heralded as a faster solution than explicit new/delete handling of memory allocation.

      This is true, but the experts fairly regularly point at java as an example of what not to do. In otherwords, as far as GC implementations go, Sun's java GC implementation is not considered very technically advanced nor Earth shattering.

    104. Re:Um, it's online by GooberToo · · Score: 1

      I feel that there are two primary objectives any language comparison tests; one is to test optimizations done by compiler/JVM and two is to compare "normal programming style" from both languages.

      I think you have a valid point there. Just the same, it's fairly well known that it requires more skill to get good performance out of C++ than it does for Java. After all, C++ isn't exactly the easiest of languages to master. Likewise, this is why java programmers are often compared to VB programmers (not that I support that view; I see real skill in many java progammers which never existed in the hordes of VB guys). In attempting to comment on the benchmarks, my goal was not to talk poorly about how well hot spot is performing. In fact, if you check my profile and read the many messages on the topic, I'm actually impressed with hot spot and how well it's working. It's just that these benchmarks, while impressive, paint a completely unrealistic view of java's performance as users are likely to encounter them in the wild.

      Based on what we've learned, it would probably be fair to asses the results as, in absoluete ideal situations, java can be as fast, if not faster than very poorly coded and less then well optimized c++ in less than ideal situations. Which, doesn't exactly match the original author's voice. Not by a long shot.

      I do agreee with you that tests are not fare from the first stand point, as C++ test incurs overhead of destroying objects. However, isn't this standard programming style for C++?

      Again, I think your point certainly has merit. Just the same, if you look at the code, one could argue that the c++ code was put together in a manner to represent a worst case performance picture.

      As for programming style, I think it's unreasonable to think that most C++ programmers would of implemented most of the code as had been done, at least the code that I've looked at. You could argue that the C++ was a literal translation of the java code, whereby, it avoided many obvious and common sense implementation, "styles".

      I do agreee with you that tests are not fare from the first stand point, as C++ test incurs overhead of destroying objects. However, isn't this standard programming style for C++? How often have you built resource managers and how often have you used them for small objects, like strings?

      Well, it depends. I have built and implemented my own heap managers, even under C. If absoluete performance is the goal, as one would expect of a benchmark, then it's certainly not out of the ordinary to implement your own new/delete operators. In other words, it's actually not that uncommon. If you look at fairly popular toolkits, such as ACE, you find that many/most of the objects and patterns specifically allow for your own memory management implementations. The reason being, that's the power of C++. Which is often the reason why C++ is used. To be redundant, it's silly to purposely avoid areas open to significant optimizations when performance is the stated goal. Thusly, it highlights just how unfair the tests were.

      Just FYI, even a moderately decent heap implementation could of optimized the current 200,000,000 deletes, within the objinst benchmark, into something as little as two deletes, assuming enough memory exists. If we assume enough memory doesn't exist for all object instances, then we could still easily reduce the number of deletes by something in the area of 10,000 orders of magnatude. Regardless, either provides significant reduction in workload, to say the least. That translates into a TON of work suddenly removed from the C++ side of the scale.

      I like java very much and I am very glad to see that these days it is being compared to C++ and people ARGUE about which one is faster. Just few years ago the argument would be about "hey, performance is not what Java is all about!

      I can't argue with that. Just the same, I think pragmatically, java is going to be significantly slower

    105. Re:Um, it's online by Trepalium · · Score: 1

      Okay, after much trial and error, I've concluded that you must be posting in "Plain Old Text" mode. The "HTML Formatted" mode I normally use changes multiple spaces to a single space, and filters out  , even in tags. The end result is that is just plain broken in HTML mode, so it's a bug in slashdot.

      --
      I used up all my sick days, so I'm calling in dead.
    106. Re:Um, it's online by GooberToo · · Score: 1

      I run all of my tests with -server, however, I had already change my config file to do that by default, thusly, making the common line option redundant. I used it mostly just so I could cut-n-paste the commands here so that its use would be obvious.

      I should offer, than for the few tests I can, I did not seem much of a difference between -client and -server, though, I sure there are many situations where that would not hold true.

    107. Re:Um, it's online by GooberToo · · Score: 1

      Shocking! Program takes advantage of language features! How dare they!

      Coward is right! It is shocking because they took advantage of a language feature under java but failed to do so under C++. Likewise, the benchmark is built around the entire concept of creating a best case situation for java and crap design/code for C++.

    108. Re:Um, it's online by Anonymous Coward · · Score: 0

      This is no big news to me, I pointed it out years ago on the Coccon user group.

    109. Re:Um, it's online by Anonymous Coward · · Score: 0

      There is no itoa function.

      Sure there is:

      void itoa() {
      printf("Shut the fuck up\n");
      }

    110. Re:Um, it's online by Trinition · · Score: 1

      That's simply not true if you expect benchmarks to reflect real world applications. Sure, it might be true for trivial utilities but for applications that stay alive for long periods of time chugging along, which is probably the majority of the worlds useful applications, it makes the results invalid. Or, at a minimum, sets greatly unrealistic expectations.

      No, it is true. THink about. What application do you know of that uses 100% of the CPU? Consider a GUI which spends most of its time waiting for user input. BY deferring memory cleanup until the garbage collector feels like doing it, you can make the GUI respond quicker because it's not watsing valuable repaint time cleaning up Objects as temporary objects outlive their usefulness. Instead, the GC can run while the human is reading the results just painted to the screen.

      A GUI is an extreme example. But consider anytime the processor can't continute, like when it's blocked on I/O or something. These are the same principles that allow multi-process, multi-thread systems to work better.

    111. Re:Um, it's online by Trinition · · Score: 1

      I'd write pooling code to handle the objects instead

      Actually, object pooling may hurt!

    112. Re:Um, it's online by angel'o'sphere · · Score: 1

      While your idea is not wrong I don't agree.

      Calling System.gc() ALLWAYS causes a gc, EXCEPT: gc is allready running, OR: you are on a VM not supporting gc.

      The language spec lets it open for one reason: there are VMs thinkable where you don't have gc, e.g. real time VMs (see the new real time java spec).

      In general you will use a plain vanilla VM, and such a VM does start collecting as soon as you call System.gc().

      Having a gc run in a low priority thread does not change much. That thread gets high priority as soon as the application runs out of memory.

      the completion of System.gc() does not appear to actually indicate that collection is anywhere near completion.

      This and your other thoughts heavyly depend on what kind of gc currently is activated (a Server VM supports different gc approaches which are activated via command line switches).

      On a real time VM, of course returning from System.gc() does NOT mean that everything is collected. It only means that the maximum time allowed for gc is over ... or less, and then everything is collected.

      On a concurrent gc, more or less the same is true, However, that is not specified in the specs. You could run the same program on two different VMs and call System.gc() at the same point during execution and both VMs can behave completely different.

      One could take it as hint, one could make a complete collection, one could make a collection freeing at least X MB memory (or everything if less than X MB is garbage) and one could spend at max Y msec in collection or collect everything, if that is possible in less than X msec.

      But most of the time ALL of those gc schemes would start a gc imediatly when System.gc() is called.

      angel'o'sphere

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    113. Re:Um, it's online by Pieroxy · · Score: 1

      Java VMs are written in C++ among other languages

      Are you implying that because they are written in C++, they are inherently slower? Because that would be sooo wrong...

    114. Re:Um, it's online by cakoose · · Score: 1

      No. Coalescing a bunch of 'delete' calls will not help much. Though the cache hit rate will probably go up, it will still be fundamentally different from the way GC works.

      'new' and 'delete' are relatively expensive in that they have to maintain complex data structures to keep track of free space. A copying garbage collector only really needs a couple pointers. The allocation operation is very, very, very fast (pointer increment). The collection operation's running time is an increasing function of how much live data there is.

      What they *could* do is try strapping on the Boehm GC to C++. But then they'd be comparing the JVM to a C++ setup that nobody uses.

    115. Re:Um, it's online by Trepalium · · Score: 1
      My point was merely that in any Real program, it's very likely the garbage collector will be called. In these benchmarks, it's unlikely it's ever called. A performance-wise analogy to C++ would be to create the objects and never free them. It's bad programming practice, but it would make the C++ and Java versions just as dishonest about their speed. Although, it would be a valid benchmark for one part of the process -- object creation.

      I think GC is a great idea that a good implementation of which could lead to increased performance in a lot of situations.
      I'd agree, except for one thing. Most garbage collected languages seem to assume that one-size-fits-all. When I was writing some C# code, I found myself wanting a delete operator, not because I wanted to clean up memory, but because I wanted to expliticly say that "I am done with this object, please do not allow me to use it further" as a guard against some programming mistakes I might make. In a C++ program, I'd get an access violation as I tried to access already freed memory, but there was no way of getting this kind of runtime error in C#.

      Unfortunately, after reading stuff from the designers of the language (mainly telling users, 'you don't need that'), I was disappointed with their attitude of academic snobbery. They had the same attitude when it came to macro expansion, or anything else that language designers fault for the collapse of civilisation.

      --
      I used up all my sick days, so I'm calling in dead.
    116. Re:Um, it's online by GooberToo · · Score: 1

      Consider a GUI which spends

      Except that, as I understand it, Java, by far, used used in server applications. Thusly, high load over extended durations should be considered the norm and not the exception.

    117. Re:Um, it's online by cakoose · · Score: 1

      I think he was talking about C++ (where pooling would help).

    118. Re:Um, it's online by Sinterklaas · · Score: 1

      I didn't assert that Java was bad. Personal disappointment is certainly my right.

      The way you brought it I think most people would interpret it as saying that Java was indeed bad. It would be very different if you would have been disappointed in the benchmark, but this read as Java bashing without good arguments to back it up.

      Actually, my "benchmark" was not flawed at all. It did exactly what it was supposed to do.

      No, what you purported to show was that 'fair' memory handling would change the result. However, your benchmark does anything but show fair memory handling for Java. Java is supposed to do gc when it is convenient and make the most of available memory. Inherently, that means that it has an advantage for:
      - programs where all the objects fit in the allocated memory
      - programs where processing is, at least part of the time, non-CPU bound

      Of course, there are also disadvantages to gc (and non-performance advantages). Garbage collection makes Java more useful for some uses and less useful for others. Exploring and quantifying these issues intelligently would certainly be interesting.

      What my result attempted to prove was that these benchmarks were flawed and that they were purposely hiding java's gc overhead.

      The benchmarks are only flawed in that respect if you want to generalize them for 'big' applications where gc will hamper processing (which does not have to be the case). However, it is simply impossible to alter the benchmark to account for all possible gc scenario's. Therefore, the best thing to do is probably to create seperate benchmarks for gc, which you can interpret based on the specifics of the application that you want to build. However, it is unfair to criticize a benchmark for not showing gc overhead when that doesn't have to be an issue in reality (for some kinds of apps).

      What my "benchmark" also showed is that java's gc overhead can be significant.

      Well duh. That is only surprising if you don't know Java at all.

      It also highlighted the fact that since c++'s new and delete operators can be overloaded, a fair comparison would be to make the c++ implementation perform the same collection deferment.

      Sure, gc collection libraries exist for c++. That would be so much more meaningful than simply killing Java's performance by doing something Java programmers are told not to do the instant they are introduced to gc.

      Take them with a grain of salt but walk away with the lessons learned.

      Creating good benchmarks (where the results are accurate and meaningful) is very hard and I'm certainly not able to do so (since it requires you to know every possible way to skew the results, knowledge that few people possess, and a certain attitude). Trust me, you can't do it either, so go easy with the wise old sage stuff.

      "A man doesn't know what he knows until he knows what he doesn't know." -- Laurence Peter

    119. Re:Um, it's online by cookd · · Score: 1

      Look, I've read Stroustrup's book, Special Edition, cover to cover. It's good stuff. And I program in C++ every day, and have done so for over a decade. I bet you $5 I know C++ MUCH better than you do. I've also graduated from college and been in the industry for a few years. I've learned a lot that goes beyond whatever sound bites Bjarne gave you (a lot more than I can put down in a slashdot posting).

      I wasn't comparing Bubble Sort and QuickSort. I was giving an example of how you can do something that is less efficient from one point of view (QuickSort has a much larger code and data requirement than Bubble Sort) but is more efficient from another point of view (QuickSort is O(n log n) and Bubble Sort is O(n^2)).

      I'm not bashing C++ as a language (though I've got plenty of ammo for that if you want it - C++ has some serious defects). I'm saying that Java and/or other VM-based architectures can and do outperform C++ and other "bare-metal" architectures. You can do an end run around my argument by saying that C++ could be run in a VM as well, but that defeats your initial argument that Java isn't efficient.

      As far as a C++ VM, it exists. The Visual C++ compiler versions 7 (aka 13) and higher can compile C++ for a virtual machine (the Microsoft CLR). The resulting bytecode can be managed (i.e. use garbage collection, stay type-safe) or unmanaged (use pointers directly, be binary compatible with the equivalent native code). So it isn't just theory, it is real. As a test, some guys ported Quake to managed C++ and found that it actually performed fairly well.

      But the issue isn't between C++ and Java. Both languages are appropriate for their applications. C++ was designed for bare metal, and does quite well for that. Java, C#, and other languages were designed for a VM architecture and they do quite well for that. C++ doesn't really work well in a VM, and there are problems trying to get Java and C# to run well outside of a VM.

      The issue is whether VM bytecode can outperform fully compiled code. And this isn't just theory. You can already go to benchmarking sites and see that in some applications, a VM can outperform native code. It all depends on the situation. I gave a list of some of the factors that can help VM code be faster, and there are more waiting to be discovered.

      In any case, you missed my point. Garbage collection using external libraries in C++ has serious issues because C++ simply wasn't designed with garbage collection in mind. Yes, it can work in some cases, but there are problems (nondeterministic destruction, leaks due to false pointers, etc.). To use C++ well in a VM, you have to change the way you write C++. The issue of low level/high level languages doesn't hold any water, since different languages apply to different problems, and I'm not concerned about languages here, just VM versus native.

      As far as Java and C++ being on the same level -- they simply aren't. You can set up frameworks and template libraries to try to boost C++ up to the level of abstraction enjoyed by Java and C# programmers (such as the boost libraries and the STL), but even with these libraries C++ still doesn't match Java and C# in many areas. You have to properly USE those C++ libraries, and they are often fairly complicated to use correctly.

      However, the case of resource initialization = allocation IS something that fits into this discussion. I use this idea as much as possible in the C++ code that I write. However, it doesn't tell the whole story by itself. What about deallocation? Not everything can go on the stack and be automatically deallocated on function exit. And even if it could, sometimes that isn't even as efficient as it could be.

      First of all, yes, you can hide all of the memory management stuff in proper classes. That's better than C. But even better than hiding your memory managment stuff is not having any memory management stuff. The runtime can do it all! Instead of having to write memory management r

      --
      Time flies like an arrow. Fruit flies like a banana.
    120. Re:Um, it's online by GooberToo · · Score: 1

      The benchmarks are only flawed in that respect if you want to generalize them for 'big' applications where gc will hamper processing

      Actualy, the benchmarks are only flawed if you expect them to reflect server class applications, many workstation class applications, or think that hot spot is able to do so well outside of recursive call chains and/or tight loops where little work is actually being done. In other words, a very broad class of problems may not do so well.

      Well duh. That is only surprising if you don't know Java at all.

      Well, except that your remark is fairly out of bounds. If you apply that knowledge to real world applications which may collect, especially if they are multithreaded, it shows that someone can be in for some real surprises. Furthermore, I now know (based on some other runs I did), that it takes only a modest number of runs from the collector to significantly effect performance.

      Creating good benchmarks (where the results are accurate and meaningful) is very hard and I'm certainly not able to do so (since it requires you to know every possible way to skew the results, knowledge that few people possess, and a certain attitude). Trust me, you can't do it either, so go easy with the wise old sage stuff.

      Actually, I have a long history of measuring benchmarks which actually have meaning. I realize you're happy to ignore the ad hok results, however, I understand what they imply. I'm comfortable with the results that it provided. I took my grain of salt and am content.

      Lastly, let me say that I think you overly object to the use of java's collector. A foolish amount of overhead was purposely allowed to kill c++'s performance yet if I artificially do the same with the java benchmark, you suddenly cry flaw and bias. Well, I happen to agree (sorta), which I've previously explained several times. Either you level the playing field so that both are flawed or you level the playing field so that both are equal. I purposely knee capped the java benchmark to attempt to level it with C++. The grain of salt is, the playing field was never leveled. Just the same, the knowledge gained underscorded the serious cost accociated with java's collection. Clearly, 1:1 implementation is far more than knee capping. The real problem is, I have no idea how much use of System.gc constitutes a level field knee-cap, thusly, I take my grain of salt and place the known performance data into contect of real world applications. In otherwords, it doesn't look good. Given the time constraints of my desire to contribute something here, the path I followed offered the shortest path while requiring the largest grain of salt.

      One of the areas that I must admit I am becoming more impressed with is the call overhead of java. It appears that java is able to significantly reduce call overhead in recursive call chains. The level of reduction is simply nothing more than awesome. Of course, as I stated above, I currently have no idea if that translates into recursivce calls for anything other than trivial work in tight recursive loops.

      Sure, gc collection libraries exist for c++. That would be so much more meaningful than simply killing Java's performance by doing something Java programmers are told not to do the instant they are introduced to gc.

      Well, the trick is to find a collector that actually performs well, or at least on par in performance with Java's. On the other and, the best c++ solution would be to simply implement a deferred delete method. As an example, ideally, the 200,000,000 deletes presented in one of the benchmarks could be deferred and optimized away into as little as two deletes. I would guess that java is smart enough to be able to do such heap tricks too. My casual playing with it suggests that it can, given some of the benchmarks.

      FYI, I've already optimized two C++ benchmarks which are now faster than the java implementations. One of them is 2.2 - 2.7x times faster than java. I've sent my work to the tester. He's accepted them and stated he woudl take the fastest code for each benchmark (Cpp or java) which he gets. So, feel free to check the original pages sometime again in the near future. I suspect there will be many updates.

    121. Re:Um, it's online by oldwarrior · · Score: 0

      HaHaHaHaHaHaHa, whew, Sniff!

      right.

      --
      If it were done when 'tis done, then t'were well it were done quickly... MacBeth
    122. Re:Um, it's online by Anonymous Coward · · Score: 0

      Calling System.gc() all the time is stupid. 'Nuff Said

    123. Re:Um, it's online by ipfwadm · · Score: 1

      However, if your code is actually trying to do something else, it really is just a "hint" as the other poster stated.

      Would it make you feel better if I spawned a thread to do nothing but increment an integer, then in the main thread call System.gc() at 500 ms intervals? This pegs my CPU usage at 100%. (I'd set the counting thread to Thread.MAX_PRIORITY, but since I'm in Windows at the moment and don't feel like rebooting to Linux, this effectively locks up my machine). At any rate, the [Full GC] still gets printed out, twice every second. Would you like me to spawn off an additional thread as well, this one to perform endless disk I/O? How about socket I/O? Or do a whole lot of graphics processing? Do whatever you want; every time you call System.gc(), [Full GC] is printed on the console.

    124. Re:Um, it's online by Anonymous Coward · · Score: 0

      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.

      JNode is a kernel written in Java.

  2. I agree. by James+A.+S.+Joyce · · Score: 0, Redundant

    "...the more people who know about present-day Java performance, the better."

    This person will never know how right they were!

  3. Good! by Anonymous Coward · · Score: 0

    Java Rulez!

  4. The Great Computer Language Shootout by thebra · · Score: 4, Informative

    Correct link

    1. Re:The Great Computer Language Shootout by Anonymous Coward · · Score: 1, Interesting

      Why are people modding him up as informative, when it's well known that you can't link to the shootout from Slashdot? I'm guessing none of the mods clicked on the link...

    2. Re:The Great Computer Language Shootout by Anonymous Coward · · Score: 1, Funny

      as we are computernerds we can write a plugin that adds a "use no referer" option to the context menu for links, or we can simply copy paste links...

    3. Re:The Great Computer Language Shootout by Digital+Avatar · · Score: 1, Flamebait

      Of course not. They just saw a link and say, "Ooooh, this guy is helpful"... +1 Informative! Of course, neither of us should really bother mentioning this, since it's well known that slashdotheads never read the fucking article, so why should they be expected to follow a link? Never think too highly of slashdotters, and you'll never be disappointed.

    4. Re:The Great Computer Language Shootout by Jahf · · Score: 1

      Well spoken from a fellow slashdotter.

      Troll. /. is like any other diverse congregation of people ... some read the article and others just listen to the person talking about the article. Lumping them altogether is insulting ... then again since you recursed yourself into the insult I guess I don't mind so much.

      --
      It is more productive to voice thoughtful opinions (reply) than to judge (moderate) others.
    5. Re:The Great Computer Language Shootout by Digital+Avatar · · Score: 1, Offtopic

      And like any other congregation of people, Slashdot attracts a particular demographic, which in this case consists of barely-literate baboons who think that by virtue of being able to admin linux boxen their nuts are elephantine, indeed titanic compared to others.

      Everyone likes to think they don't fit into that category. Everyone likes to think they're a beautiful , unique snowflake... but they do, and they're not.

      The truth of the matter is that there is such a thing as a stereotypical slashdothead, and the stereotypical slashdork doesn't read the article, nor does he follow useful links.

      Instead of sticking your fingers in your ears and pretending that this is a troll, and slashdot is filled with some random sampling of people (only part of which are morons), why not admit to the fact that slashdot _is_ full of morons and try _doing_ something about it? For example:

      Stop modding up goatse boys. It's not funny. It never was.

      Bring the whole American/European pissing contest in every thread to a screeching halt.

      Instead of posting under threads where you have no damn earthly reason to be doing so by virtue of your crass ignorance of the topic at hand, try sticking to topics you _do_ know something about.

      When Taco-head posts a dup... don't bother reaming him in the forums... he doesn't read those either.

      If the Slashdotties could just follow these simple rules, it'd make the world a better place, with pretty pink flowers and unicorns!

    6. Re:The Great Computer Language Shootout by Jahf · · Score: 1

      Woah pardner ... you've now stomped your own debate twice:

      1) calling all /.ers baboons (I'm not going to bother going back to the original to see what the first quote was) when you're still obviously a /.er

      2) Pointing out that there is a stereotypical /.er ... is there one? Sure ... but by definition a stereotype doesn't define the whole. In fact, it often doesn't even describe the majority. It only describes the most obvious-to-the-outside faction. ... if ya don't like it, go away. Yeah, I bit on the flamebait again, but yeesh you are either doing it on purpose (in which case you are quite happy right now) or you are a complete idiot wasting your time here (religious zealots do it all the time to hear themselves rail at society ... you wouldn't be a Southern Baptist would you?)

      Your suggestions are all fine ... and I make a point of putting people who follow them on my friends list. However ... this is /. ... a free community forum that you don't pay squat for (well, unless you have a subscription, you don't do you?). You don't get to make up any rules ... the people who pay for the site do. The only rule you get to make up is:

      * If I don't like /. and it annoys the everliving crap out of me, I shall not post about it, I shall simply leave as there is surely another site on the net that would welcome my cybergoth mentality.

      And go ahead and post again ... it might show you're not just trolling ... but I won't be replying as we've both lowered the signal:noise ratio enough for one thread.

      --
      It is more productive to voice thoughtful opinions (reply) than to judge (moderate) others.
  5. Yes but... by Anonymous Coward · · Score: 2, Funny

    how does it corner?

  6. Sorry, no. by Anonymous Coward · · Score: 0, Informative
    Java Faster Than C++?

    No, it isn't. It's much slower.

    I wrote a program that simply counts to 10000 and then quits. Time from double-clicking the icon until when the program exits:
    C++: 0.5 seconds
    Java: 20 seconds
    How hard is that?
    1. Re:Sorry, no. by Anonymous Coward · · Score: 0

      This reveals the inherent weakness of benchmarks. They are statistics, and you can make them lie for you anytime you want.

      Perhaps in long-running code once the JIT has had a chance to run, the Java code performs better.... it all depends on the type of benchmark.

    2. Re:Sorry, no. by Ianoo · · Score: 4, Funny

      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.

    3. Re:Sorry, no. by Anonymous Coward · · Score: 0

      You're spot on there. Java compiled might be as fast, but it's still slower because I have to wait to compile the stupid thing before it runs.

      You'll never get Java to be down to same "speed" as C/anything else. It just can't work that way.

    4. Re:Sorry, no. by mveloso · · Score: 1

      Wow, I counted from 1 to 10,000, and it came out much faster. How good of an example is that?

    5. Re:Sorry, no. by SpaceCadetTrav · · Score: 1

      How scientific.

    6. Re:Sorry, no. by Morgahastu · · Score: 1

      Yes. Very scientific. Was it the first time you ran the program? If so than the program is compiled. It's not anytime you run it after that.

      Was that JVM running? If not then it had to load the very large VM before running the program.

      Try running it a second time and then report back.

    7. Re:Sorry, no. by Anonymous Coward · · Score: 0

      Did you take into account Java starting the JVM? And did you use the server VM as the article suggested?

      Even so, sometimes "faster" processes are not faster for relatively small tasks. For example, Quicksort is accepted as a faster sorting algorithm than Selection Sort. But, for sorting small numbers of items, Selection Sort is faster! You have to be sorting quite a few items before you see the benefit of Quicksort, and eventually it is MUCH faster than Selection Sort.

    8. Re:Sorry, no. by bckrispi · · Score: 1

      This is simply because there is a certain amount of time that it takes the JVM to start up. Once it's up and running, you should see these numbers converge. Setting up a more accurate test, I leave as an excercise for the reader.

      --
      Xenon, where's my money? -Borno
    9. Re:Sorry, no. by kaffiene · · Score: 2, Insightful

      You're measuring startup time, not execution speed.

      Duh.

    10. Re:Sorry, no. by shadowmatter · · Score: 5, Interesting

      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

    11. Re:Sorry, no. by stratjakt · · Score: 1

      Explain the difference to a non-technical end-user.

      Mozilla takes a minute or so to load, IE pops right up. Rendering speeds really mean shit, since the bottleneck is a dial-up modem that's lucky to get 33.6 on a good day. Now, explain to my grandmother that Mozilla is "faster".

      Anyways, since I dont feel like replying twice, I sincerely doubt he'll reproduce his results against VC++ or Intel's compiler. gcc is all about being compatible against a wide range of architectures - it's not optimized for any single architecture in the least.

      Ah, anyways it's just food for zealots and fanboys. It varies from compiler to compiler, VM to VM, and doesn't seem to take into account memory overhead (needing to swap to disk makes your uber-routine SLOW no matter what you do).

      It also doesn't take into account that Java's UI widgets, Swing and whats-its-face, make your application look like something from the Apple IIe's in my gradeschool library.

      Java fans rejoice, C++ fans seethe, in the end it's pretty much irrelevant out in the real world.

      --
      I don't need no instructions to know how to rock!!!!
    12. Re:Sorry, no. by Anonymous Coward · · Score: 0

      Apart the fact that you are a troll (no way something like i++ in a loop would take in *both* languages more than one sheduller swith), I'll take a bite: Java can have startup time in the range of several sec (depends on the machine, of course). But still the article results are not representative for most tasks...

      PS: "Informative" moderators are idiots...

    13. Re:Sorry, no. by bckrispi · · Score: 1

      Sorry, I've never noticed a problem with the startup time on Mozilla running on Win98 SE: AMD Duron 750 mhz, 256mb. I see the "mozilla is slower than IE" argument on /. all the time, but I have yet to experience it.

      --
      Xenon, where's my money? -Borno
    14. Re:Sorry, no. by Demandred · · Score: 1

      I just wrote a java program to do just that...without printing each value to the console and it takes 0.218 seconds.

      --
      "...Beer..."
    15. Re:Sorry, no. by SoCalChris · · Score: 1

      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.

      By your own admission, the Java code was still twice as slow as C++.
      Perhaps you should have said 19.51 seconds was the JVM starting/stopping? :)

    16. Re:Sorry, no. by Anonymous Coward · · Score: 0

      C++: 0.5 seconds?

      yeah, well my ship can go .5 past light speed...

      sorry for the off topic comment, couldn't resist ;-)

      seriously thought, I'd say, you better stick with the C++ programming if that's the speed difference that resulted from your own programming.

    17. Re:Sorry, no. by Knight2K · · Score: 3, Interesting

      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.

      --
      ======
      In X-Windows the client serves YOU!
    18. Re:Sorry, no. by maraist · · Score: 3, 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.

      --
      -Michael
    19. Re:Sorry, no. by afidel · · Score: 3, Interesting

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

      --
      There are 4 boxes to use in the defense of liberty: soap, ballot, jury, ammo. Use in that order. Starting now.
    20. Re:Sorry, no. by Mr+Tall · · Score: 1

      I get this - mozilla takes a good few seconds (5-10) to start up compared to IE. (Athlon 1800 @1.8GHz, 512Mb RAM)

      I put up with this, because IE is a stinking piece of shit.

    21. Re:Sorry, no. by phasm42 · · Score: 4, Funny

      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.

      --
      "No one likes working in a hamster wheel, and your shop smells of cedar shavings from here." - TaleSpinner
    22. Re:Sorry, no. by kraut · · Score: 3, Insightful

      >A VM otoh does get this capability for free.
      TANSTAAFL ;)

      > Java enforces garbage collection, and thus optionally gets the particular performance gain
      Err... whether garbage collection gains or looses you performance depends very much on your application. I am not convinced that any garbage collector can even be theoretically faster than automatic variables.

      >As was pointed out, one of the strenghts of C/C++ are pass-by-value....
      After programming in C++ for 14 years, I don't think I've heard that one before

      >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
      const &? Ever heard of const references before? I don't feel qualified to judge your Java programming, but it's evident you're not particularly familiar with C++.

      I'd be interested to know how you have more control over the design of 3rd party libraries in Java than in C++.

      --
      no taxation without representation!
    23. Re:Sorry, no. by mattyrobinson69 · · Score: 1

      ie starts up so fast because most of it is already in memoryy (windows explorer - the desktop).i use opera and ive not used moz for a long time, but i heard about an option to make it run in the background (like IE and MS Office do)

    24. Re:Sorry, no. by 0x0d0a · · Score: 1, Insightful

      It might become less significant.

      But I get cranky when I click a button and the application doesn't, y'know, appear.

      If I have to wait for 19 seconds for anything to appear, I'm not going to be a happy camper, ignoring what technical reasons cause the slowdown.

      Furthermore, from a technical standpoint, Java has a number of fundamental performance flaws:

      * Java bounds-checks all array accesses. This is pretty par for the course for safe languages, and it's a good bet that compilers optimize some of this out, but it's a hit.

      * Java technically can avoid rapid allocation/deallocation by use of object pools and use of primitives and the like. However, it's *very easy* to have an excessive number of allocation/deallocations. The language definitely encourages this.

      * Java lacks generics (I haven't checked out 1.5, not sure whether this can provide performance improvements). This is bad because casting and hence run-time typechecking has to take place every time an object in a container is accessed.

      Plus, Java eats memory for breakfast. Yes, memory is cheap and all that, but as a user, I'd definitely take a C/C++ app over a Java app any day.

      Java's great for lightweight networking, it's nice that it has a cross-platform GUI, and it's good for rapid development due to the scads of library functionality.

      The problem is that it got way overhyped as a C/C++ replacement (which it isn't) or even a good choice for general application development (including horizontal-market client stuff) which it isn't.

    25. Re:Sorry, no. by aled · · Score: 1

      1, 10000. That would make... er... two numbers. Wasn't that pretty fast?

      --

      "I think this line is mostly filler"
    26. Re:Sorry, no. by maraist · · Score: 2, Insightful

      While you make several good points. I do have some counter-points.

      A VM otoh does get this capability for free.

      Let me qualify this as saying you don't have to do or pay for anything extra to achieve this.

      Err... whether garbage collection gains or looses you performance depends very much on your application. I am not convinced that any garbage collector can even be theoretically faster than automatic variables.

      By automatic, if you mean stack-resident variables, then I agree (with the caveat of dangerous code design), but if you mean malloc'd variables, then I don't see what the problem is. malloc has to worry about a great number of things, not least of which is memory fragmentation. I happen to have done a non-trivial amount of research on memory allocators; though I am no expert. Memory allocators can be optimized for allocation speed, fragmentation efficiency, concurrency, cache coherence, etc. but not all (obviously). As it happens, a copying garbage collector gives you all of the above EXCEPT when your buffer runs out; and thereby requires a garbage collection. So long as you you have large heap and you're not worried about the latency from garbage collection, then copying collectors are VERY fast. Allocation is literally a mutex lock, a stack-pointer range check, a stack-pointer increment, then a mutex unlock.

      Now, because latency is often a real issue, most modern GC's apply additional complexity/logic which slows down the normal case to minimize the worst case; e.g. generational garbage collection which may require read or write boundry op-codes inserted. But code-wise, these varients are identical. Thus you achieve a flexibility not possible in a dynamic-memory-egnostic system such as c/c++.

      I'd be interested to know how you have more control over the design of 3rd party libraries in Java than in C++

      I didn't really mean design, but environment; Specifically in terms of the dynamic memory allocator. But, just to make the differentiation complete, java allows byte-code load-time modification. This is very common in "aspect oriented programming" such as in the database realm (JBoss/OJB) or object proxying. In Java, by introspection you can prepend/append/search-replace method calls or even individual instructions as need be. Note that this isn't any different than a custom pre-processor for C, but tends to be cleaner and thus doesn't require the [3rd party] coder to adhere to a particular convention.. Moreoever, this works on already shipped binaries, as opposed to requireing preprocessing to occur on the original source code.

      --
      -Michael
    27. Re:Sorry, no. by vsprintf · · Score: 1

      Was that JVM running? If not then it had to load the very large VM before running the program.
      Try running it a second time and then report back.

      Let me get this straight. You're saying people who use Java programs should always run them once as a warm-up, then run them again for real. Hey, it makes sense to me. :)

    28. Re:Sorry, no. by Anonymous Coward · · Score: 1, Informative
      I think you forgot to use -O3. If you had, your c program would run a 2 instruction loop: decrement, branch. I seriously doubt you found a way to write a faster program in assembly. ;)

      Input:
      int i;
      for (i = 0; i < 1000000000; ++i) {
      }
      Output (gcc -O3):
      movl $999999999, %eax
      .p2align 4,,15
      L6:
      decl %eax
      jns L6
    29. Re:Sorry, no. by jarich · · Score: 1
      You left one out... your Palm sync software is written in Java last time I checked.

      Anyone think that it's too slow?

    30. Re:Sorry, no. by Anonymous Coward · · Score: 0

      Java technically can avoid rapid allocation/deallocation by use of object pools and use of primitives and the like. However, it's *very easy* to have an excessive number of allocation/deallocations. The language definitely encourages this.


      Bof the GC this is not the issue that it is in C++. For example if you're writing high performance C++ code you'll often end up with private heaps and specialized allocators that are designed to reduce the cost of many allocations in a short period. Other times you'll make use of these heaps to allow you to quickly free large amounts of memory. In either case you do it because the allocation or deallocation cost is too high (because it needs to ensure it doesn't fragment memory horribly).

      In Java (and C#/.NET as well as well) though you typically have a garbage collector that can move memory around. This allows the garbage collector to not care about where it allocates memory from. It can fragment it to all hell, and clean up later. And the GC can even optimize clean up later to allow it to quickly reclaim large areas of memory (as for the cost of this it can often be done when the program would otherwise not be doing anything).

      So this is really less of an issue then normally considered. If your allocator is as simple as:

      result = foo;
      foo += size;

      Then you really can't get much better than that. Throw in per/thread allocators like these and you get contention-free allocation which is completely kick ass for multi threaded systems.

      And this is the one of the areas that I know of where a VM can beat C++ in speed. And it makes sense: Java can't beat C++ in code gen. Maybe it can be as good, but it has a limited time to create code. The C++ compiler can be slow and it doesn't matter.

      So the only way Java can win is by having better algorithms. Memory is the one area where they've really done a good job. Exception handling may be another area where they're better (as Java can more readily use runtime information for exception handling while typically C++ implementations update state as they enter/leave exception blocks).

      Of course, I didn't read the article, so maybe they mentioned these areas...

    31. Re:Sorry, no. by pdbaby · · Score: 1

      Interestingly, in Java 1.5, generics are actually syntactic sugar to make your code look pretty. When you define an int list or a String list, it just creates an object list and prepends a cast to your object accesses.

      You may (or may not) be interested to know that C#'s implementation of generics actually creates a separate piece of code to handle things without casts, etc.

      --
      Global symbol "$deity" requires explicit package name at line 2. - If only $scripture started "use strict;"
    32. Re:Sorry, no. by 0x0d0a · · Score: 1

      Interestingly, in Java 1.5, generics are actually syntactic sugar to make your code look pretty. When you define an int list or a String list, it just creates an object list and prepends a cast to your object accesses.

      Ah, thank you. Yes, this is sort of what I was suspicious of when reading the 1.5 feature list, but I hadn't read anything on it from any language people yet.

    33. Re:Sorry, no. by Anonymous Coward · · Score: 0

      I don't give at rat's ass what language its in or how big it is, 19 seconds for start-up and shutdown time is too fucking much

    34. Re:Sorry, no. by Anonymous Coward · · Score: 0

      "And the GC can even optimize clean up later to allow it to quickly reclaim large areas of memory (as for the cost of this it can often be done when the program would otherwise not be doing anything)."

      so what if the app doesn't have a period when its not doing anything?

      "Of course, I didn't read the article"

      fucking typical

    35. Re:Sorry, no. by Anonymous Coward · · Score: 0
      Not rebutting your point about obscure settings, but...
      The point he is making is that it doesn't matter to the end user who "cheated" in what way:
      • IE cheats by using already running parts of the OS
      • C++ cheats by compiling to a "instantly" runnable binary instead of using the currently-in-fashion interpreter mode.
      • perl cheats by having complex re crap that runs from the command line
      • Python cheats by having the parser instantly throw up an error because of fast-to-parse whitespace rules
      • asm cheats by being close personal friends with the processor.
      • Java cheats by requiring 11 guys to screw a lightbulb into Weblogic.
      One way of benchmarking is to time the click on icon or hit return on command line to task completion. That is a perfectly valid benchmark for a wide variety of programs. Wider probably than the "wait for/exclude caveats" then start timing category.
    36. Re:Sorry, no. by jmccay · · Score: 1

      The July 2004 C/C++ Users Journal covers Java and C++. It has an article on Java's new generics, and it is not better than C++'s. It's a step in the right direction, but not better.

      --
      At the next eco-hypocrisy-meeting, count the private jets used to get to the meeting. Should be interesting to see that
    37. Re:Sorry, no. by 0x0d0a · · Score: 1

      Bof the GC this is not the issue that it is in C++. For example if you're writing high performance C++ code you'll often end up with private heaps and specialized allocators that are designed to reduce the cost of many allocations in a short period. Other times you'll make use of these heaps to allow you to quickly free large amounts of memory. In either case you do it because the allocation or deallocation cost is too high (because it needs to ensure it doesn't fragment memory horribly).

      In Java (and C#/.NET as well as well) though you typically have a garbage collector that can move memory around. This allows the garbage collector to not care about where it allocates memory from. It can fragment it to all hell, and clean up later. And the GC can even optimize clean up later to allow it to quickly reclaim large areas of memory (as for the cost of this it can often be done when the program would otherwise not be doing anything).


      Mmm...I dunno if I can agree with you here. I don't think the overriding cost is likely to be simply in the GC to allocate a block of memory -- it's in the allocation and handling of metadata and in the execution of constructors. I'm also a little surprised that a JVM would do defragmentation (clearly it's possible, yes). The only general-purpose defragmenting PC-class system that I've run into is the (now obsolete) classic Mac OS, which initially ran on hardware lacking an MMU or hard drive and thus really needed to defragment what was there. Defragmentation got a lot less valuable and more expensive when quantities of memory involved rose.

      So the only way Java can win is by having better algorithms. Memory is the one area where they've really done a good job.

      I just can't agree. It's easy to see that Java-implemented software requires significantly more memory (I've yet to see software with a C++ and a Java implementation where the C++ implementation requires more memory), and I can't see how GC vs allocation/destruction costs are likely to be significantly more than constructor runtimes (I *have* seen some convincing arguments based on more researchy, performance-oriented software like ML).

    38. Re:Sorry, no. by dasmegabyte · · Score: 1

      Since you should be bounds checking every array ANYWAY, I don't see where that hit matters. It's certainly not visible in any of the performance Java work I've done.

      Yeah, Java can let you be lazy with object creation and destruction. So can C++. At its best, though, Java is a happy medium that can adjust to just about any available amount of memory.

      Speaking of which, if you don't want Java to become a memory hog, cut it off! Use a smaller maximum heap, 64 meg is enough for pretty much everything (and for most utilities, 4 meg is a dream). Since Java won't run GC until a certain percentage (70-80%) of its maximum allocation is filled up, it's almost always going to be resting at near maximum allocation. I wouldn't worry about it too much, with modern swapped memory, most of those old references are sitting quietly on your hard drive, hoping that you'll need them.

      And generics are coming, as is a greatly improved UI speed. Incidentally, one of the reasons Java UI is so slow is that most developers, lazy things that we are, let Java object perform their own updates and paintings. If you want a snappy GUI, you HAVE to do all redraws yourself. This is the only way to prevent the whole window from flickering every time a control's state changes, which besides being annoying means you just created and destroyed a bunch of objects for no real reason other than you can't be bothered to track the mouse.

      --
      Hey freaks: now you're ju
    39. Re:Sorry, no. by maxwell+demon · · Score: 2, Funny

      Well, actually, an ideal optimizer would detect that this loop has no observable behaviour, and therefore optimize it away completely. That is, the complete loop would be compiled to zero instructions and executed in zero time. Of course, a perfect Java compiler could do the same, which of course gives the question of how many times faster Java zero time is to C++ zero time :-)

      --
      The Tao of math: The numbers you can count are not the real numbers.
    40. Re:Sorry, no. by mmusson · · Score: 1

      Little benchmark programs like this do not look at the two weakest areas in Java.

      A large program will have bad performance until the garbage collector is tuned very carefully. My experience is running java server programs and we can get much improvement from careful tuning which is a iterative and time consuming process. But in no way are these systems close to the speed of raw C++ code. We routinely move bottleneck code to external C++ to improve performance.

      Also the lack of destructors is a fundamental language flaw. In C++ it is a common pattern to allocate a resource in the constructor and free it in the destructor. Java can't do this and consequently serious resource leaks are very common in Java systems. Seasoned teams end up writing code that tracks every reference to a resource in order to make sure they are cleaned up.

      Its possible that sometime in the future Java will narrow the performance gap with C++ for general applications but it won't be anytime soon.

      --
      SYS 49152
    41. Re:Sorry, no. by Anonymous Coward · · Score: 0

      Too bad I need to have at least two MCSE's on hire to keep Windows "properly maintained".

    42. Re:Sorry, no. by sploxx · · Score: 1

      Why, oh, why is C++ ALWAYS COMPARED TO ASSEMBLER?!

      C++ is at least as poweful and expressive as java. Java is C++ dumbed down and with a nice and fairly complete class library. And no, (I hear this often), Java is not preceding C++ historically, the C++ _standard_ came later than the first versions of Java.

      But C++ is not assembler. C++ has a high dynamical range. Use it for assembly-like tasks, e.g. kernel programming, use it for writing your traffic control, expert system, whatever.

      It is a general purpose language.

      I do both, C++ and Java, and although Java has adavantages (mainly, the platform to run the programs is readily on nearly every computer - But with C++ one does 'write once, compile everywhere' nowadays with boost and similar libraries), the programming language forces the programmer to do various things considered "better for him/her".

    43. Re:Sorry, no. by Anonymous Coward · · Score: 0

      >const &? Ever heard of const references before? >I don't feel qualified to judge your Java >programming, but it's evident you're not >particularly familiar with C++.

      No kidding... between that and a few other points in this thread (the C++ test case, for example, where for no reason somone put an object on the heap rather than on the stack) wow. These are not guru-level hyper-complex C++ programming practices... very basic stuff here.

    44. Re:Sorry, no. by mattyrobinson69 · · Score: 1

      i dont mind cheating with performance except MS Office. MS think its so important that they have it partly loaded in memory for you. i use MS office very rarely, the rest of the time its just hogging memory that it doesn't need to.

    45. Re:Sorry, no. by excessive · · Score: 1
      Since you should be bounds checking every array ANYWAY, I don't see where that hit matters.

      Because you don't always need to bounds check? If you've got a circular buffer, for example, you only really have to bounds check it on the update to the index. (Or pointer if you're being perverse...)

    46. Re:Sorry, no. by jeremyp · · Score: 1

      "Thus "clean" code in c++ will be copy-intensive"

      In C++ use a reference to a constant e.g.

      int foo (const MyClass& bar)
      { ...
      }

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    47. Re:Sorry, no. by sulli · · Score: 1

      And that doesn't even count the multiple browser crashes.

      --

      sulli
      RTFJ.
    48. Re:Sorry, no. by Trinition · · Score: 1

      *Sigh*, yes, it's true. At least Sun finally seems to be warming up to client-side Java with the partial startup optimizations coming in 1.5 and the recent JDIC project opening.

      There is a much more agressive plan, though, that could lead to a Java shell to allow a much faster starting of client-side apps.

  7. Java may be fast but ... by Anonymous Coward · · Score: 0, Troll

    ... C++ is more portable.

    1. Re:Java may be fast but ... by bgoss · · Score: 1

      "but C++ is more portable" That's priceless. Were you able to type that with a straight face?

  8. If you don't run the JVM... by Anonymous Coward · · Score: 0

    no one should ever run the client JVM when given the choice

    If you don't run the JVM, how do you run your code?

    1. Re:If you don't run the JVM... by Tar-Palantir · · Score: 4, Informative

      He claims you should use the server JVM instead, stating that it is faster but slower to startup and consumes more memory.

    2. Re:If you don't run the JVM... by Anonymous Coward · · Score: 0

      Man, you're stupid.

  9. Netcraft Confirms: by BandwidthHog · · Score: 3, Funny

    Fact: C++ is dying....

    Oh hell, I don't have the heart. Nevermind.

    --

    Quantum materiae materietur marmota monax si marmota monax materiam possit materiari?
    1. Re:Netcraft Confirms: by Lost+Dragon · · Score: 1

      C++ is dying? Nah, it hasn't even reached the 20-year "beleaguered" mark yet.

    2. Re:Netcraft Confirms: by Emperor+Shaddam+IV · · Score: 1

      Yeah, sure. Like Cobol, RPG, and C are dead. Yet there are still jobs and a lot of banks and telcoms STILL run Cobol MF systems to this day. PL/I is dead. C++ still lives.

    3. Re:Netcraft Confirms: by the_mad_poster · · Score: 1

      Nah. That just means banks and telcoms are dying.

      Hey wait....

      --
      Alito: A vote for Alito is a punch in the eye to put that bitch back in her place!
    4. Re:Netcraft Confirms: by Emperor+Shaddam+IV · · Score: 1

      And yet they still get most of our hard-earn salary... :)

    5. Re:Netcraft Confirms: by Anonymous Coward · · Score: 0

      "Never mind" is two words.

    6. Re:Netcraft Confirms: by Anonymous Coward · · Score: 0

      Sure it is.
      All the upcoming versions of Windows will be written in Java.

      All the upcoming versions of Linux will be written in Java.

      All the upcoming versions of MacOS will be written in Java.

      All the upcoming Unix versions will be written in Java.

      Virtually all cluster applications and high end computing software will be written in java in their next versions.

      Embedded devicses will add more memory just so they can run a JVM.

      The majority of games coming out next quarter will be in Java.

      The web servers running this site will all be written in Java.

      Is this "dying" the same as "Apple is dying"?

      Java is great for servlets - it really shines there. For everything else, it's bloated slow and a waste of resources.

      "Java have no pointers - funny the #1 error is null pointer exception"

      I realize you're joking, but man, it's amazing how many people believe this.

    7. Re:Netcraft Confirms: by Anonymous Coward · · Score: 0

      Oh well whatever, nevermind.

    8. Re:Netcraft Confirms: by pdbaby · · Score: 1

      OH GOD! The banks don't keep my money, do they? I thought I was giving it to them to safeguard for me...

      --
      Global symbol "$deity" requires explicit package name at line 2. - If only $scripture started "use strict;"
  10. Anyone got a match? by nebaz · · Score: 5, Funny

    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.

    --
    Rhymes that keep their secrets will unfold behind the clouds.There upon the rainbow is the answer to a neverending story
    1. Re:Anyone got a match? by Anonymous Coward · · Score: 0

      Don't forget the classic "Your /. number is bigger than mine"

    2. Re:Anyone got a match? by DAldredge · · Score: 0, Offtopic

      vi = editor
      emacs = os

      Why are you comparing them to each others?

    3. Re:Anyone got a match? by Anonymous Coward · · Score: 0

      And you smell funny.

      i knew i shouldn't have changed my deodorant!

    4. Re:Anyone got a match? by Anonymous Coward · · Score: 0

      I must admit I AM a Linux N00B, but I have used both Emacs and Vi and As far as I know they were both editors and nothing more.

    5. Re:Anyone got a match? by Anonymous Coward · · Score: 0

      anything else?

      No. Nothing compares to Java.

    6. Re:Anyone got a match? by Anonymous Coward · · Score: 0
      What is Emacs? To quote the Emacs Manual: Emacs is the extensible, customizable, self-documenting real-time display editor.
      see for yourself
    7. Re:Anyone got a match? by deconvolution · · Score: 1
      Here is another one:

      MS Windows is cheaper than Linux ...

    8. Re:Anyone got a match? by Anonymous Coward · · Score: 0

      But it is YOUR mommy who wears boots!

    9. Re:Anyone got a match? by Anonymous Coward · · Score: 0

      I must admit I AM a Linux N00B, but I have used both Emacs and Vi and As far as I know they were both editors and nothing more.

      That's what those emacs people want you to believe! Vi is the way.

    10. Re:Anyone got a match? by Anonymous Coward · · Score: 0
      No emacs is...

      jk, you're right, everyone knows vi, or maybe vim, or maybe gvim is clearly the best

    11. Re:Anyone got a match? by SquadBoy · · Score: 1

      Cisco vs Checkpoint

      --

      Cypherpunks: Civil Liberty Through Complex Mathematics. Those who live by the sword die by the arrow.
    12. Re:Anyone got a match? by Anonymous Coward · · Score: 0

      dont listen to these people! vi rules!

      (so does kde, slackware, linux)

    13. Re:Anyone got a match? by SphericalCrusher · · Score: 1

      It's pretty funny that you say "BSD is better than Linux" if you say "GNOME is better than KDE"... normally, people who think something is better than Linux are KDE whores. Despite this offtopic fact though, I agree with whoever mentioned that C++ is only slower because it has to start up from a virtual machine. Even if C++ IS somehow slower than Java, C++ tends to all of my needs and does whatever I need it to do. At the point where it's not quick enough for me anymore, then maybe... I'll use another language that is a lot quicker. since I know it'll be a little while before that happens.

      --
      "Instant gratification takes too long." - Carrie Fisher
    14. Re:Anyone got a match? by glwtta · · Score: 1

      For this to become a flamewar, wouldn't someone (anyone) have to still give a damn about C++?

      --
      sic transit gloria mundi
    15. Re:Anyone got a match? by Brandybuck · · Score: 1

      normally, people who think something is better than Linux are KDE whores. Despite this offtopic fact though...

      You're right, it is offtopic, but you're wrong in your assertion that it's a fact. The GNOME and KDE communities on FreeBSD seem to be equal in size and activity.

      --
      Don't blame me, I didn't vote for either of them!
    16. Re:Anyone got a match? by ignorant_newbie · · Score: 1

      >I agree with whoever mentioned that C++ is only
      >slower because it has to start up from a virtual
      >machine

      I know this is slashdot, but please... there's a reason for the 'preview' button.

    17. Re:Anyone got a match? by Dun+Malg · · Score: 1
      my dad can beat up your dad.

      I always wanted someone to say this to me. Then I could say "Really? That's great! Send him over after dinner. I'll get some candy corn and we can sit on the porch and watch!"

      --
      If a job's not worth doing, it's not worth doing right.
    18. Re:Anyone got a match? by SphericalCrusher · · Score: 1

      ...trying to get some mod points? With stupid comments like that, you're never going to get any. *points at you and laughs*

      --
      "Instant gratification takes too long." - Carrie Fisher
    19. Re:Anyone got a match? by Anonymous Coward · · Score: 0

      my milkshake is better than yours...

    20. Re:Anyone got a match? by Anonymous Coward · · Score: 0

      You forgot to mention that your mother dresses you funny. ;-)

    21. Re:Anyone got a match? by SlashdotKeefey · · Score: 1

      Oh god, I hope you don't mind me saying this, but I absolutely detest vi. The amount of times I've had to start all over again because I just happen to have pressed the wrong, obscure, key sequence.

      I'm not a UNIX buff, but I did find EMACS quite pleasant to use (in a Wordperfect 5.2 kind of way), once the billions of key sequences had been learnt, but vi is unbearable and unforgiving.

      Now give me DevStudio any day of the week... (waits for backlash...)

    22. Re:Anyone got a match? by Anonymous Coward · · Score: 0

      Karma is not given for funny anymore, anyway.

  11. Ah...yes... by Anonymous Coward · · Score: 1, Insightful

    The great thing about language benchmarks is that there are so many to choose from...

    1. Re:Ah...yes... by globalar · · Score: 1

      Benchmarks capture an implementation of an implementation of an implementation. If you could recurse back through all that, you might be able to draw better general conclusions. However, in the same amount of time you can run your own results. (Which one gets you published or on /.?)

      Incidentally, how old is this benchmark?

  12. meh by jnapalm · · Score: 2, Funny

    i tried to get first post with my C++ autoposting application...but its too damn slow.

    1. Re:meh by mobby_6kl · · Score: 1

      I also tried to get First p0st, but not only my Java prog was slow, it was also buggy and posed a reply to comment #9435018 instead of the story...

  13. Just one game by sien · · Score: 1, Interesting

    Are there any sizable 3D games, i.e. code that really needs performance written in Java?

    1. Re:Just one game by Troed · · Score: 1

      Yes, on cellphones.

    2. Re:Just one game by SteroidMan · · Score: 1

      Not until someone ports either OpenGL or DirectX to Java. OpenGL has a JNI implementation (blech!), and last time I checked Microsoft was banned from ever touching Java again. Summary: Fat chance.

    3. Re:Just one game by Mindcry · · Score: 2, Informative

      unreal uses a java like scripting language, but its for gameplay code, not the actual rendering, however, i think that's as close as it comes right now. (the java like stuff is something like 20x as slow as the c++ code, cause of the overhead etc)

      P.S. a lot of gameplay code is also in c++ and compiled into dll's (i believe), but mods dont have access to the headers to compile c++ code into the game readily.

    4. Re:Just one game by kaffiene · · Score: 1

      The OpenGL bindings for Java work just fine and there's no reason why any individual couldn't write a wrapper for DX for Java if they so wished.

    5. Re:Just one game by iabervon · · Score: 1

      Code that really needs performance is done in hardware these days. Writing your rendering engine in a serial programming language is 8 years out of date.

    6. Re:Just one game by sqlrob · · Score: 1

      Vampire: Masquerade

      Granted, it's dirty java with a bunch of JNI classes.

    7. Re:Just one game by focitrixilous+P · · Score: 1

      Not all that sizable, or good for that matter, but there is a Java MMORPG called Runescape, which is in semidecent 3D landscapes with Godawful sprites for players. Last time I played, a true 3D version was in Beta, it's probably out by now. Still, in the name of Java vs. C++ you could kill some rats. Registration is required, and there is a nice tutorial island. It's ad supported, so watch out.

      --
      SAILING MISHAP
    8. Re:Just one game by Psymunn · · Score: 1

      Oh those thinsg
      Is it just me or shoudl my friends cellphone not have more loading time then a 486 running XP, with spyware turned to full?
      tried to play a simple game on a fone and got fed up because of all the damnloading bars. For waht? a crappy bmx game that lasted 30 seconds
      back to snake for me...

      --
      The Neo-Bohemian Techno-Socialist
    9. Re:Just one game by Bugmaster · · Score: 1

      Actually, if you read the article, you'll see that Java is actually faster than C++, at least according to the benchmarks. The reason there are no 3d Java games is that raw speed is simply not enough -- you also need hardware acceleration (graphics, sound, etc.). Hardware acceleration is system-dependent, whereas Java is supposed to be system-independent, so Java can't do it. There were several attempts to marry Java to OpenGL or something like that, but none have been successful AFAIK.

      --
      >|<*:=
    10. Re:Just one game by bwt · · Score: 1

      Wyvern is a free 2D MMORG coded in java and jython.

    11. Re:Just one game by Mindcry · · Score: 2

      i did read the article, but i kinda think i'd need to see more than one source as well as hear comments about any flaws in the tests before accepting this as the new order.

    12. Re:Just one game by Pieroxy · · Score: 1

      the java like stuff is something like 20x as slow as the c++ code

      Maybe they should switch to real java then... Cause this story is all about it being faster than C++.

    13. Re:Just one game by Anonymous Coward · · Score: 0

      "Wyvern is a free 2D MMORG coded in java and jython."

      well then that would make it fucking off-topic huh?

    14. Re:Just one game by 1lus10n · · Score: 1

      and I could never ever ever post something thats an opnion on the intrarweb and have people think its a fact.

      God sakes man even the clip from the story says "in certain situations" which means: when java is coded by a really good coder and we use crap C code, and a crap C compiler.

      Hell parts of java and the JVM are WRITTEN in C++.

      --
      "Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe." --Albert Einstein
    15. Re:Just one game by Troed · · Score: 1

      Well then, maybe you have the wrong phone? There are new phones with very capable Java engines - even Java3D - with very nice games.

  14. What are -client and -server? by JoshuaDFranklin · · Score: 4, Informative
    1. Re:What are -client and -server? by gtrubetskoy · · Score: 1
      From the Sun FAQ:

      The client system is optimal for applications which need fast startup times or small footprints, the server system is optimial for applications where the performance is most important. In general the client system is better on GUIs.

      Is it just me, or is the Java world full of gratuitous assertions?

    2. Re:What are -client and -server? by Jennifer+E.+Elaan · · Score: 4, Informative
      "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).

    3. Re:What are -client and -server? by Anonymous Coward · · Score: 0

      You don't 'turn on' the Java inliner per se. Some JIT's (hotspot server in this case) inline _at_runtime_ automatically. They can even inline virtual method calls.

      In C++ you can only inline non-virtual methods. And it introduces a host of other problems (bloat, binary compatibility).

      Java inlining is a more general solution to the problem. Whether or not it's 'fair' in this context-- well that's up to interpretation.

    4. Re:What are -client and -server? by Anonymous Coward · · Score: 3, Interesting
      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).

      It does mean something. However, here's something a little odd about the differences between C++ and Java: in C++, the compiler makes the decision about what to inline before it fully knows what is calling what. That is because the compiler runs before the linker. So C++ is working with more limited information. Meanwhile, the Java virtual machine has everything integrated. The compiler (the JIT) and the linker (the class loader) and the loader (also part of the class loader) run all together and can cooperate and communicate.

      Why is this important? Because the C++ compiler must make all kinds of guesses when it makes these optimizations. If you have a 1-line function, it probably makes sense to inline it in every place it's called, because the speed will increase and the code size won't (the inlined code will probably be smaller than the code to make a function call). But say you have a 25-line function. Should you inline this? If it's called only in one place and nowhere else, it's still more efficient. But if it's called in 50 places, you waste a lot of space by making 25 copies of the function. So maybe you should inline it only in the one or two places where it counts. OK great, but which two places are these? The C++ compiler is left having to just guess. The Java virtual machine can instead just observe the program as it runs and *know* where inlining is worth it and where it isn't.

      Also, what if you have a really small function in a library and you want to inline that? Well, in C++, if you dynamically link to that library, you *can't* inline the function. It's just not possible. But with Java, you can, because it's all just classes that are loaded by the class loader and then translated into machine code as needed. So you can inline functions that come from dynamic dependencies, like system libraries.

      And then, as someone else said, Java can even inline virtual method calls! How can it do this? Again, by observing the conditions the code is *actually* executing under, not by theorizing about all possible conditions it might execute under. C++ has to allow for the possibility that every object is a different class and so must use a v-table. But Java can, in theory at least, know that while the object *could* be an instance of class X, Y, or Z, in reality the class loader has only loaded class Z, so therefore all instances must be instances of class Z. Presto, inlining is possible, at least until class X or class Y is loaded. But then, since the code is generated dynamically, when you load class X or Y, you could trash the inline code you generated and start over with virtual method calls now that you are having to plan for a different situation.

      I should point out that you can get 99% of these performance boosts in C++ by hand-tweaking your code. You can figure out which methods need to not be declared virtual and remove the "virtual" keyword from those methods. If you need to make an inline call to some function in a system library, you can manually copy the code from that library into your source code and call it, as long as you're willing to rewrite and rebuild your C++ app when the library code (that you copied) changes. So these things are theoretically possible, but they are such a code maintenance and system administration nightmare, that they are virtually always far from practical. But with Java or other similar languages, they can all happen for you automatically behind the scenes.

    5. Re:What are -client and -server? by Anonymous Coward · · Score: 0

      I just reran some benchmark code I wrote for my current project with the -server option. In my case the performance was worse. It is certainly worth evaluating your code's performance with both VMs before arriving at your release configuration.

    6. Re:What are -client and -server? by roofingfelt · · Score: 1

      Hmm, trying Eclipse with -server setting to see if it runs better on v.large projects...

    7. Re:What are -client and -server? by Anonymous Coward · · Score: 0

      Given that all methods in Java are virtual, it's not surprising that it can inline some virtual methods.

  15. Developers: World Flat, Sky Green by random+coward · · Score: 0, Troll

    And Microsoft is more stable than Linux.

    1. Re:Developers: World Flat, Sky Green by Anonymous Coward · · Score: 0

      Microsoft isn't an OS. It's a company.

  16. He used g++ to compare C++ with Java... by exp(pi*sqrt(163)) · · Score: 4, Insightful

    ...on x86? Please! Wake me up when someone who knows enough about C++ to pick a decent x86 compiler runs some benchmarks.

    --
    Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
    1. Re:He used g++ to compare C++ with Java... by Sebastopol · · Score: 1

      what's wrong with g++? i've only ever used intel's compiler besides, and it wasn't much faster for a finite-element circuit simulator that I wrote.

      --
      https://www.accountkiller.com/removal-requested
    2. Re:He used g++ to compare C++ with Java... by crawdaddy · · Score: 2, Funny

      You really see a difference in the infinite-element circuit simulators, though. That's probably what he's referring to.

    3. Re:He used g++ to compare C++ with Java... by Anonymous Coward · · Score: 1, Insightful

      But that's what 100% of all C++ programs on your Linux computer are compiled with.

    4. Re:He used g++ to compare C++ with Java... by ky11x · · Score: 5, Informative

      g++'s goal is modularity for ease of porting in cross-platform cross-compiling. aggressive optimization is not one of its strengths. the point of such benchmarks is really not a language comparison, but a comparison between the code generated by the most optimized compilers for that language on a specific platform. Using g++ for this simply causes the study to lose credibility

    5. Re:He used g++ to compare C++ with Java... by exp(pi*sqrt(163)) · · Score: 4, Informative

      g++ isn't great at optimizing. For code I write it's somewhere between 0 and 50% slower than MSVC. It depends a lot on the type of code of course. For pure numerical work I think the Intel compiler usually scores highly so I'm surprised you're not seeing much difference.

      --
      Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
    6. Re:He used g++ to compare C++ with Java... by Anonymous Coward · · Score: 0

      Not true. Oracle on Linux is compiled w/ the Intel C++ compiler

    7. Re:He used g++ to compare C++ with Java... by cyfer2000 · · Score: 2, Insightful

      "Hi, I am a professor from X university, and I was wondering if we could get a license of your compiler for research?"

      "I am sorry, blah blah blah..."

      "May I talk with your boss?"

      "Sure, just a second...du...du..."

      "Hi, can I help you?"

      "Hi, I am a professor from X university, and I was wondering if we could get a license of your compiler for research?"

      "Ah...May I know your research topic?"

      "It's about the speed of C++ and java...blah blah blah"

      "As a company sponsored a lot of research, you know, we'd like to support your research, but, you know...blah blah blah."

      "So how much it could be?"

      "something between your arm and your leg"

      "I am going to think about it, thank you for your help, have a nice day"

      "you too, feel free to contact us, bye."

      "Bye"

      "OK, boy, we use gcc firstly, and after we got enough funding, we may buy a better compiler!"

      "Yes, sir, and the result of GCC is here."

      "Nice..."

      --
      There is a spark in every single flame bait point.
    8. Re:He used g++ to compare C++ with Java... by Anonymous Coward · · Score: 0

      I've seen G++ do about 10% to 15% better then Intel on some stuff I did ... lots of FP stuff and lots of STL vector manipulations. I tried every trick in the book, and G++ still came out ahead.

      Now on some other stuff I've done, Intel was > 20% faster then G++

      Just need to pick the right tool

    9. Re:He used g++ to compare C++ with Java... by vlad_petric · · Score: 2, Informative
      Try inter-procedural optimizations. For that you have to give icc/icpc the -ipo flag, and furthermore use xiar instead of ar and xild instead of ld.

      The results might shock you.

      --

      The Raven

    10. Re:He used g++ to compare C++ with Java... by Sebastopol · · Score: 1

      yes, your experience sounds very familiar to mine. i do tight FP loops (some recursive) that iterate on a bunch of stl containers in a non-local pattern through memory.

      --
      https://www.accountkiller.com/removal-requested
    11. Re:He used g++ to compare C++ with Java... by Alban · · Score: 1

      (about gcc - perhaps a bit of topic)

      Well every compiler has something wrong. However, there seemed to be a better than average compiler study last summer in C++ Users Journal that outlined a few interesting things. The study was for intel compilers by the way.

      What I remember of gcc/g++ is that while it was said to generate decently efficient code (still behind vc++ and intel's compiler though), it generated very fat code. The binaries were significantly larger then the ones generated by other compilers.

      gcc is also the most compliant C++ compiler. It is actually perfectly compliant. It also generates very clear compiler messages, while microsoft's are often cryptic.

    12. Re:He used g++ to compare C++ with Java... by willCode4Beer.com · · Score: 1

      Suprised because he used the compile that ships with most linux distros?

      --
      ----- If communism is a system where the government owns business, what do you call a system where business owns govern
    13. Re:He used g++ to compare C++ with Java... by mwillis · · Score: 5, Informative

      Intel gives their c++ compiler away free for non-commercial hobbyist use on linux.

      The windows version has a free trial that runs for 30 days.

      Try it. See if it makes a difference. If it doesn't, torch it. If you find it makes your critical code run 2x faster, then... have a look at what a computer that runs 2x faster will cost you, and then decide what to do.

    14. Re:He used g++ to compare C++ with Java... by Anonymous Coward · · Score: 0
      g++'s goal is modularity for ease of porting in cross-platform cross-compiling.

      Like Java?

      aggressive optimization is not one of its strengths.

      Ok, you got me there. It helps when you have big bucks to throw at developers like Sun can.

    15. Re:He used g++ to compare C++ with Java... by CoughDropAddict · · Score: 3, Informative
    16. Re:He used g++ to compare C++ with Java... by exp(pi*sqrt(163)) · · Score: 1

      What does Linux have to do with it? It's a story about Java and C++.

      --
      Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
    17. Re:He used g++ to compare C++ with Java... by exp(pi*sqrt(163)) · · Score: 1

      I'll second that. Template metaprogramming generates notoriously complex error messages but I've found that with g++ you can actually claw your way through them to figure out what the problem is. But check out MSVC 7.1 which is pretty standards compliant these days.

      --
      Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
    18. Re:He used g++ to compare C++ with Java... by gid · · Score: 1

      Sure there's exceptions, but the vast majority of c++ applications are compiled with g++. There's no denying that.

    19. Re:He used g++ to compare C++ with Java... by spectecjr · · Score: 1

      "So how much it could be?"

      "something between your arm and your leg"


      The MSVC optimizing compiler is a free download from Microsoft. So that's not much of an excuse.

      Intel's highly efficient optimizing compiler - at only $399 (much cheaper than, say Metrowerks Codewarrior at upwards of $5,000 for a license for the Coldfire CPU) - is a steal.

      You can also sign up for a free trial of Intel's compiler if you so desire. Or at least you could last time I checked.

      So no, there's no good excuse for running these test using GCC. The only reason to do so is ignorance, laziness, or to deliberately skew the results.

      --
      Coming soon - pyrogyra
    20. Re:He used g++ to compare C++ with Java... by DunbarTheInept · · Score: 1


      gcc is also the most compliant C++ compiler. It is actually perfectly compliant. It also generates very clear compiler messages, while microsoft's are often cryptic.

      Not necessarily. I spent quite a bit of time once trying to figure out why g++ was bitching at me for the error "choosing over because that is the closest match to ." This sounds like a warning, but it was listed as an error and it refused to go on.

      What was bad about this message is that it lied. G++ was NOT choosing that version in the slightest. It was trying (and failing) to tell me that the problem was that it was ambiguious which one I meant and it was choosing NEITHER, and thus couldn't go on.

      The compiler message told me it was "choosing to do foo" when in reality it wasn't able to tell if it should do foo or not, and that was the actual error.

      (The problem was that I had two methods that had some defaulted parameters in just such a way that it was ambiguous which one I meant when I left the defaulted parameters out. The error I admit was real, and was my fault. My beef was that the compiler's message was telling me the compiler was doing something it clearly was not.)

      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

    21. Re:He used g++ to compare C++ with Java... by Anonymous Coward · · Score: 0

      The optimized output of gcc 3.4 is much improved. A couple of people doing benchmarking in the Gentoo forums have been comparing with Intel's compiler.

      The single most effective flag (in terms of faster code) is -ftracer in 3.3 and later. 3.4 adds others of interest.

    22. Re:He used g++ to compare C++ with Java... by GooberToo · · Score: 1

      Using g++ for this simply causes the study to lose credibility

      I'm sorry, but that statement holds no merit. The g++ compiler is considered a defacto implementation for many, many platforms, including Linux. While g++ is clearly not the fastest of compilers, it is certainly used-a-plenty. If you're running Linux, chances are, all of your applications have been compiled with it. Furthermore, the java that was being used in the same benchmark, was probably also compiled with it (it's compiled c++, right?). So, your dismissal is nothing more than a ploy. Seriously, if you think your logic holds merit, then you must dismiss any and every benchmark you've ever read about that was run on Linux.

      Now then, what you can't say from these bechmarks is that java is faster than C++. These benchmarks don't prove that. What they do say is, for the benchmarks ran, java was running close to and in some cases faster than GNU's g++ compiler.

      The simple fact that java is actually getting in the same ballpark as g++ is certainly slashdot news worthy. Also, keep in mind that I've also considered myself to be a pro-C++ kind of guy. Frankly, everytime I start to learn Java, I get disgusted. I actually don't care for the language much. But...it's clearly getting faster and deserves it's hard fought recognition.

    23. Re:He used g++ to compare C++ with Java... by GooberToo · · Score: 1

      I guess you're happy to ignore the fact that g++ is the defacto compiler on the Linux platform? You happy to ignore that gnu's compilers are used on the applications that just about everything else is benchmarked against.

      You're just not happy with the results.

      Frankly, I've not look at much code yet, so I'm trying to figure out if the benchmarks actually have any merit. But, dismissing them because you didn't like the results (which is what your excuse boils down to), is simply not fair. Ya, g++ is clearly not the fastest compiler but it is the compiler that most Linux applications are compiled with. Dismissing it because you simply want to, is what's not fair.

    24. Re:He used g++ to compare C++ with Java... by SporkLand · · Score: 1

      I'm in a compiler group at a major university, and microsoft is more than happy to give us software and support.

    25. Re:He used g++ to compare C++ with Java... by spectecjr · · Score: 1

      I guess you're happy to ignore the fact that g++ is the defacto compiler on the Linux platform? You happy to ignore that gnu's compilers are used on the applications that just about everything else is benchmarked against.

      You're just not happy with the results.

      Frankly, I've not look at much code yet, so I'm trying to figure out if the benchmarks actually have any merit. But, dismissing them because you didn't like the results (which is what your excuse boils down to), is simply not fair. Ya, g++ is clearly not the fastest compiler but it is the compiler that most Linux applications are compiled with. Dismissing it because you simply want to, is what's not fair.


      It's a benchmark. We're benchmarking performance. Compiling it with a compiler which is not designed to optimize well is NOT a good benchmark.

      And by the way, this site is News for Nerds, not News for Linux Zealots. Java runs on Windows too. In fact, MOST if not nearly all Java code runs on Windows systems by sheer weight of numbers.

      Besides... you've already proven in other threads that you don't know jack about programming, so please, butt out troll.

      --
      Coming soon - pyrogyra
    26. Re:He used g++ to compare C++ with Java... by spectecjr · · Score: 1

      Suprised because he used the compile that ships with most linux distros?

      That doesn't mean that Java is faster than C++. About all you can conclude from it, in fact, is that the C++ compiler that ships with most Linux distros can't optimize worth a damn and needs a lot of work.

      --
      Coming soon - pyrogyra
    27. Re:He used g++ to compare C++ with Java... by GooberToo · · Score: 1

      Troll??? WTH? Talk about ignorant trolls. What a dolt.

      It's a benchmark. We're benchmarking performance.

      And your point is?

      Compiling it with a compiler which is not designed to optimize well is NOT a good benchmark.

      Why?

      And by the way, this site is News for Nerds, not News for Linux Zealots.

      RTFA. It was benchmarked on Linux.

      Java runs on Windows too. In fact, MOST if not nearly all Java code runs on Windows systems by sheer weight of numbers.

      And....if you have a point, make it.

      Besides... you've already proven in other threads that you don't know jack about programming, so please, butt out troll.

      What an ignorant, small minded troll you are.

      Basically, you're calling me a troll because you clearly don't know anything about programming, insist that a a test is invalid just because you think g++ is slow, and because you think the tests should be run on windows? WTH? Can you prove that you're any more of an idiot? Worse, I offered a polite and direct counter point and your response is to attack and avoid answering any of the raised questions. What a tiny mind you have.

    28. Re:He used g++ to compare C++ with Java... by DroopyStonx · · Score: 1

      Yeah but... if you check the results, you'll notice that on quite a few occasions that Java was MORE than twice as fast as C++.

      Now, I know nothing about the g++ compiler and benchmarks against a more suitable compiler for x86, but it's hard to believe that g++ would be twice as slow as the rest.

      Even if speed was doubled in the C++ compiler, Java still shows some pretty impressive results.

      Again, I'm not aware of how g++ compiles vs others, so it could very well be twice as slow (or more).

      --
      We have secretly replaced these Slashdot mods' sense of humor with a rusty nail. Let's see if they notice!!
    29. Re:He used g++ to compare C++ with Java... by spectecjr · · Score: 1

      Worse, I offered a polite and direct counter point and your response is to attack and avoid answering any of the raised questions. What a tiny mind you have.

      Hmmm... maybe it's just me, but I certainly don't think you can claim to be offering a "polite and direct counter point" when you've already marked me as a "foe", and last time we debated anything, you acted like a completely idiotic gimp for the entire thread.

      Go away.

      --
      Coming soon - pyrogyra
    30. Re:He used g++ to compare C++ with Java... by Anonymous Coward · · Score: 0

      given that the JVM gives certain optimization advantages over statically compiled C++, since the person who undertook the study didn't choose the C++ compiler with that greatest optimizations for speed, it lessens the credibility of the study when it's point was to compare the speed of the two languages. the report on the study wasn't framed in the context of comparing compilers (although that's actually what occured). sheesh, even the title of his study alone shattered its credibility.

    31. Re:He used g++ to compare C++ with Java... by GooberToo · · Score: 1

      Seems I've been validated in my action of marking you a foe. You might want to take a look at your self to figure out why I lashed out at you. And, bluntly, it's because you asked for, just as you did now. You were as wrong then as you are now.

      Go back a reread what I posted. I did offer a polite counter point. You attacked, and insanely, you clearly don't even have a leg to stand one. That's what puts you over the edge of being an idiot.

      Go on. Prove me wrong. Go back and reread my post. Act like a child you want, but that hardly validates your childish behavior.

      And, I'll point out, again you dodge supporting your view point. The reason is fairly obvious. You clearly don't have a leg to stand on so your last resort is to attack the person. I think I'm seeing a pattern here.

      Here's the previous message to which you attacked:

      I guess you're happy to ignore the fact that g++ is the defacto compiler on the Linux platform? You happy to ignore that gnu's compilers are used on the applications that just about everything else is benchmarked against. [so, how can this make the comparison unfair??]

      You're just not happy with the results. [is it rude to point ot the obvious here?]

      Frankly, I've not look at much code yet, so I'm trying to figure out if the benchmarks actually have any merit. But, dismissing them because you didn't like the results (which is what your excuse boils down to), is simply not fair. Ya, g++ is clearly not the fastest compiler but it is the compiler that most Linux applications are compiled with. Dismissing it because you simply want to, is what's not fair.

      [so, if it's unfair, why, since just about all linux applications are compiled via gnu's tools?]

      So, please let me know how I attacked you? How was I not polite? You asserted many things, can you support any of them?

    32. Re:He used g++ to compare C++ with Java... by Anonymous Coward · · Score: 0

      the study was supposedly benchmarking the execution speed of C++ versus the execution speed of JAVA, the study didn't say "JAVA versus C++ with the de-facto compiler" did it? your continuous straw man attempts are what indicates that you might be a troll, and if you can't see how a true performance benchmark of two languages requires compilers that offer the greatest speed optimizations then you sir are one who is ignorant and small-minded.

    33. Re:He used g++ to compare C++ with Java... by 1lus10n · · Score: 1

      Seriously, if you think your logic holds merit, then you must dismiss any and every benchmark you've ever read about that was run on Linux.

      Uhh No. You would have to dismiss any coding benchmarks from linux that used g++. Anyone who is worried about the speed differences between the two languages wouldnt use g++, and wouldnt use java. java is a bloated whore of a language. It takes up too many resources for the minor advantage over other similar languages. Not to mention that the average person who knows/uses java couldnt code their way out of a wet paper bag to keep from suffacating.

      It is getting faster. but it still has a long long way to go. You got it right when you said the following:

      What they do say is, for the benchmarks ran, java was running close to and in some cases faster than GNU's g++ compiler.

      Which to me doesnt say a whole frickin lot. Java zealots, now replacing VB zealots and coming to a compusa near you. "Sooooooo How much software do you want to buy today ?"

      --
      "Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe." --Albert Einstein
    34. Re:He used g++ to compare C++ with Java... by maxwell+demon · · Score: 1

      What would really be interesting would be to see how the very same Java code performs when executed on a Java VM vs. when compiled with gcj into native machine code. Because that way, the code is by definition equivalent (it's the same code!), and it would more clearly show the difference the VM makes on execution time.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    35. Re:He used g++ to compare C++ with Java... by Anonymous Coward · · Score: 0

      You're such a goober, Goober.

    36. Re:He used g++ to compare C++ with Java... by Anonymous Coward · · Score: 1, Informative
      This can be also because G++ floating point has higher accuracy than MSVC:s floating point code.

      For example, sin() calls in MSVC lead to single FSIN assembly instruction. But INTELs FSIN instruction is known to be quite inaccurate/incorrect with certain range of angles so G++ inserts code before and after FSIN which corrects the result to be more accurate. (this feature can be disabled with --ffast-math switch).

    37. Re:He used g++ to compare C++ with Java... by Anonymous Coward · · Score: 0
      gcc is also the most compliant C++ compiler. It is actually perfectly compliant.
      False. gcc does not have export, so it is obviously not perfectly compliant. gcc also fairs worse than other compilers on the proprietary standards conformance testing suites from Plum Hall, Dinkumware and Perennial. gcc is good and getting better all the time, but usually people hold up Comeau as the example of best standards compliance.
    38. Re:He used g++ to compare C++ with Java... by Seahawk · · Score: 1

      How many of the linux people use gcc as their compiler?

      I would say that 99%+ is a fair shot...

      Doesn't make more sense to compare against the compiler people actually uses?

    39. Re:He used g++ to compare C++ with Java... by Anonymous Coward · · Score: 0

      > Compiling it with a compiler which is not designed to optimize well is NOT a good benchmark.

      Why?


      If you're going to claim that (current implementations of) Java is/are faster than (current implementations of) C++, you need to use the best Java compiler and the best C++ compiler, or your claim is not valid.

      If you're going to benchmark Java against a C++ compiler which is known not to generate particularly fast code, then you cannot claim, based on those results, that Java is faster than C++, only that Java is faster than the code generated by that particular C++ compiler.

      What his tests show is that Java might be a good choice for Linux development, since the benchmarks suggest that it can produce faster code than g++. What he claims is that they show that "Java is faster than C++". See the problem?

    40. Re:He used g++ to compare C++ with Java... by GooberToo · · Score: 1

      Anyone who is worried about the speed differences between the two languages wouldnt use g++, and wouldnt use java.

      How do you plan to support such a statement? To me, you're implying that anyone using Java cares nothing for performance. Yet, you then turn and say the same thing for g++, which of course, is simply not true. While g++ is clearly not the faster compiler around, it generally doesn't do that bad of a job.

      Which to me doesnt say a whole frickin lot.

      I happen to agree, especially since more looking indicates that this is more an example of poorly writen C++ code using ideal performance corner cases for java's hot spot technology. I especially agree with your assessment since all of these benchmarks appear to purposely avoid any GC during their short runtimes. Which means, it's not even starting to reflect real world java application runtimes, which seems to common among almost all java benchmarks.

      I hope you will not confuse me with a java zealot as I am NOT a java guy. Feel free to look up my profile and read the many other messages I've posted on this subject.

      Now then, after all that, I still argue that you simply can not dismiss these benchmarks because java was compared to gnu's tools. If you insist on doing so, you must then disregard every samba vs win or apache vs iis benchmark because apache and samba are typically both compiled with gnu's tools. Likewise, so is the kernel. You ready to toss all of those winning benchmarks away?

      Simple fact is, there are many holes with these benchmarks but the compiler used does not appear to be one of them.

      If I still haven't brought you around to my viewpoint, then I guess we'll have to agree to disagree.

    41. Re:He used g++ to compare C++ with Java... by Shachaf · · Score: 0

      How many of the linux people use gcc as their compiler?

      I would say that 99%+ is a fair shot...

      Doesn't make more sense to compare against the compiler people actually uses?


      How many of the java people use the (default) -client setting for their JVM?

      I would say that 99%+ is a fair shot...

      Doesn't it make more sense to compare against the JVM setting people actually use?

    42. Re:He used g++ to compare C++ with Java... by GooberToo · · Score: 1

      reasons like this and and this are why you shouldn't get too bothered by these benchmarks.

      Hope these help shed some light on what's going on with these benchmarks. As you can see, even as poor as g++ does, it's still proving to be faster than java, and that's using ideal corner cases for java.

      If you follow the link about java's gc, I attempted to let the 1:1 gc implementation run all night. I killed it this morning. It never completed. Clearly a 1:1 implementation does not appear to be a fair comparison, just the same, it highlights that any real java application where gc does become a factor, java's performance does go out with the baby and bathwater.

      Cheers.

    43. Re:He used g++ to compare C++ with Java... by willCode4Beer.com · · Score: 1

      You are correct, it doesn't mean one is faster than the other. My experience has shown either of these can be faster than the other depending on the application. The which language is faster debate is actually pointless. A language doesn't make an application fast or slow, the developer does.

      But, taking your bait... if he uses a better C++ compiler to make the C++ code faster, then the Java camp will say that he should use the IBM compiler and Virtual machine (which is much faster than Sun's).
      Then if he does that, the C++ folks will say that he should use the Wind River or Intel C++ compiler, then the Java folks will say that he should use the JRocket VM. Haven't we heard Sun claiming since Java 1.0 that it just needs a good compiler and runtime to be faster.

      This argument is circular. The point is, he tested both using a common runtime/compiler for each. Most common linux distros have their C++ apps built using g++, this alone means that his choice of compiler was valid. Perhaps he should have mentioned the target platform to really be clear. If he were targeting windows then I would have expected VC++ as that is the most common compiler for that platform.

      There are lies, damn lies, and benchmarks.

      --
      ----- If communism is a system where the government owns business, what do you call a system where business owns govern
    44. Re:He used g++ to compare C++ with Java... by willCode4Beer.com · · Score: 1

      To continue your argument, what do compilers have to do with it?
      Java and C++ and just specifications.
      Implementation matters. Its the implementation that gets used.
      My post was in response to the previous poster claiming that the flaw in the test was the choice of compiler. My response was to indicate that the the author of the article chose a mainstream compiler for the Linux platform. I would expect that if he were testing on windows then he would be using VC++.

      --
      ----- If communism is a system where the government owns business, what do you call a system where business owns govern
    45. Re:He used g++ to compare C++ with Java... by willCode4Beer.com · · Score: 1

      Actually, you can conclude that the JVM's are getting better since previous ones were slower than g++.

      To make a conclusion about the quality of g++ we would need a comparison of g++ vs other C++ compilers, not against Java.

      --
      ----- If communism is a system where the government owns business, what do you call a system where business owns govern
    46. Re:He used g++ to compare C++ with Java... by Anonymous Coward · · Score: 0

      How about latest ICC vs. Sun Java latest 1.4.x?

    47. Re:He used g++ to compare C++ with Java... by 1lus10n · · Score: 1

      I hope you will not confuse me with a java zealot as I am NOT a java guy

      Didnt get that vibe.

      ... You ready to toss all of those winning benchmarks away?

      Yes ? I honestly think ALL benchmarks that rely on something other than just X are useless, period. In order for a benchmark to be acurate it must only use 1 variable, the variable being tested, or at least have all other variable's be the EXACT same. This is usually not possible, hence most benchmarks are utterly useless.

      You should use what suits your needs best, evaluate what you could use by testing scenario's that are likely to occur in the real world and go from there. Saying java is faster than C is moronic since its technicaly semi-impossible. Some java nut (the person/people who wrote this) wants people to use java more, yipee for him tooting his horn, and thats all this is.

      Any language that requires all of the shit that java requires (whats the size of a java SDK now ?) and has that large of a memory footprint is useless to anyone except people who only know java.

      If all I have seen is bad java code, then there must not be any good java coders.

      --
      "Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe." --Albert Einstein
    48. Re:He used g++ to compare C++ with Java... by 1lus10n · · Score: 1

      100% agreed. I knew that would be the case BEFORE I actually read the benchmark.

      I agree with most of what your saying, just not all of it. (see other post)

      --
      "Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe." --Albert Einstein
    49. Re:He used g++ to compare C++ with Java... by fatphil · · Score: 1

      Or it means he can't write C++ worth a damn.

      FP.

      --
      Also FatPhil on SoylentNews, id 863
    50. Re:He used g++ to compare C++ with Java... by Seahawk · · Score: 1

      Uhmm - yes?

      That is why he included the client wm score?

      But your 99% is probably way of - anyone using java serverside does not use the client wm :)

  17. Of course it's faster -- by ianbnet · · Score: 1

    Java uses Star Trek Transporter technology! To beam cows no less (front page of java.com, right now).

    What's C++ got? Grappling hooks?

    --
    --------------------- -me, Crusher of those who are Foolish (don't be foolish)
  18. Nort really surprising by Anonymous Coward · · Score: 0, Troll

    Just see what comes out of profiling this:

    int main( int argc, char **argv )
    {
    for ( int ii = 0; ii < 10240; ii++ {
    cout << ii << endl;
    }
    return( 0 );
    }

    Now compare it to this:

    int main( int argc, char **argv )
    {
    char s[ 2 ];
    s[ 1 ] = '\n';
    for ( int ii = 0; ii < 10240; ii++ {
    s[ 0 ] = '0' + ( char ) ii;
    write( 1, s, 2 );
    }
    return( 0 );
    }

    Guess which one's going to be several orders of magnitude faster?

    1. Re:Nort really surprising by pclminion · · Score: 4, Insightful
      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.

    2. Re:Nort really surprising by IMarvinTPA · · Score: 2, Informative

      I think you have some fatal flaws in your C code. Your string buffer isn't long enough to hold what you are doing. And they aren't doing the same thing. The first code is going to count to 10240. The second code is going to display ascii characters from null through to character 255 and then do some very bad things.

      Bad code, BAD!

      IMarv

    3. Re:Nort really surprising by furball · · Score: 0

      While that doesn't necessarily say Java is faster than C++, neither does it say that C++ is faster than Java but this algorithm is faster than the other one.

    4. Re:Nort really surprising by Anonymous Coward · · Score: 0
      Your string buffer isn't long enough to hold what you are doing

      It's not a string. It's a two-character buffer.

    5. Re:Nort really surprising by Anonymous Coward · · Score: 0

      Technically not true, the C code will display '0' (0x30) up through character 0xFF, then wrap around to character 0x00 (NUL), through 0xFF, and keep doing that over and over again (filling up the screen with lines of single-character garbage). It won't do any "very bad things", but I agree that it will do something completely different than the C++ code, and shows off the author's embarrassingly poor coding abilities more than any useful performance information.

  19. Cross platform by leakingmemory · · Score: 2, Informative

    Java's strength is mostly it's cross platform compatibility. I have never really liked C++ very much. It seems complicated to write cross-platform code with C++. (Header troubles, and all OSes seems to have it's own implementation. Ie. try to compile Linux code on FreeBSD, and opposite) As a conservative coder I therefore prefer C, which is as fast as you (the coder) make it.

    1. Re:Cross platform by Anonymous Coward · · Score: 0

      >Java's strength is mostly it's cross platform compatibility.

      [Alanna] 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 ...

    2. Re:Cross platform by swillden · · Score: 1

      I therefore prefer C, which is as fast as you (the coder) make it.

      C++ is identical to C in this regard.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  20. Benchmarks by AnomalyConcept · · Score: 1

    The benchmarks page is down. I'm getting the 'slash hole' page. Does anyone know what these benchmarks are? And, is it an accurate comparison between the object-oriented nature of Java vs. C++ (which, as far as I've done, doesn't really have true oo support)?

    1. Re:Benchmarks by thebra · · Score: 1

      Working link: LINK

    2. Re:Benchmarks by Hoodsen · · Score: 3, Interesting

      From comments Doug Bagley made about the "Shootout" (where the benchmarks came from), no, I don't think it is an accurate comparison, or at least a conclusive comparison between C++ and Java. His comments from his conclusion:

      I put it on the web because I thought it would interest others. Even though I put disclaimers on the page, and I try not to make any claims, I see some people say the shootout shows that "language X is faster than language Y".

      That claim is probably premature and hence, bogus. I suppose you could make the claim that, in "Doug's word frequency test, on a PII-450 running Linux 2.4, given a certain input, language X is faster than language Y" Assuming, of course, that I haven't made any mistakes. Some of my tests are also arguably poorly designed and meaningless. (Hey, if you have some better ideas, please write to me).

      Benchmarks are notoriously misleading, and perhaps mine aren't any better, although I do try. Benchmarks tell you about results in a very specific case. Drawing a general conclusion is problematic.

    3. Re:Benchmarks by Anonymous Coward · · Score: 0

      Who cares whether or not C++ has true OO support?

      OO is not an end in itself.

  21. Re:Caught up with the speed, but still the ugliest by mhale2243 · · Score: 3, Informative

    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.

  22. every year this happens... by Sebastopol · · Score: 0, Flamebait

    When the following two pieces of code are written in Java, I'll take it seriously:

    1) a java compiler for java (funny that the java binaries are written in C++ and compiled with a compiler written in C++)

    2) id's next game engine

    --
    https://www.accountkiller.com/removal-requested
    1. Re:every year this happens... by furball · · Score: 0

      The current java compiler for java from Sun is written in Java. It's always been written in Java.

      One down. One to go.

    2. Re:every year this happens... by Anonymous Coward · · Score: 0

      Actually, id's games are written in C.

      Carmack stated once that C++ actually slowed things down within their engines ;)

    3. Re:every year this happens... by bckrispi · · Score: 3, Informative

      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.

      --
      Xenon, where's my money? -Borno
    4. Re:every year this happens... by Citizen+of+Earth · · Score: 1

      1) a java compiler for java
      2) id's next game engine


      3) Sun's next version of Solaris!

    5. Re:every year this happens... by Sebastopol · · Score: 2, Funny

      "It's always been written in Java."

      Except for the first Java compiler. ;P

      --
      https://www.accountkiller.com/removal-requested
    6. Re:every year this happens... by Erwos · · Score: 4, Insightful

      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

      --
      Plausible conjecture should not be misrepresented as proof positive.
    7. Re:every year this happens... by Mornelithe · · Score: 1

      javac is written in java, and always has been. There's a launcher written in C for each platform, I believe, but it loads up the java classes to compile stuff.

      I'm also quite sure the Java VM is written in C for efficiency, not C++. Writing it in C++ would also add the confuston of having one object model built on another object model, which would be bad.

      However, IBM did write a Java VM (as I recall) in Java. And it was fast, although I don't recall how they ran it. I guess they compiled it to native code some how.

      I could probably produce evidence of this, but you can look it up just as easily as I can. I forget what the VM was codenamed. Jalapeno or something like that.

      --

      I've come for the woman, and your head.

    8. Re:every year this happens... by foidulus · · Score: 1

      However, IBM did write a Java VM (as I recall) in Java. And it was fast, although I don't recall how they ran it. I guess they compiled it to native code some how.
      The standard Java compiler will allow you to compile your code into a binary for the platform you are on. However, this ruins the Write-Once-Run-Anywhere property, which Sun was really going for, so they don't really advertise the fact that it's there.

    9. Re:every year this happens... by Mornelithe · · Score: 1

      Link:

      Jikes RVM

      Written in Java. It was codenamed Jalapeno.

      --

      I've come for the woman, and your head.

    10. Re:every year this happens... by xlv · · Score: 1


      "It's always been written in Java."

      Except for the first Java compiler. ;P


      And how's that different from C++? Unless you believe the first C++ compiler was written in C++...

    11. Re:every year this happens... by ky11x · · Score: 1

      Your first example would be meaningless. Compilers are IO-bound, not CPU-bound.

    12. Re:every year this happens... by kaffiene · · Score: 1

      This is a great example of how clueless the /. language bigots are regarding Java. Your lead point is wrong now and always has been.

    13. Re:every year this happens... by Yrd · · Score: 1

      I don't know about id, but Epic have been using C++ for the Unreal Engine for years now. The documentation for the version supplied with The Wheel of Time specifically states that it's written in C++, with UnrealScript providing some of the run-time code (and fodder for mod authors muahahaha).

      C++ is a pretty cool language. I don't care about the results of a benchmark that says Java is faster. Why not? Because I really, really hate programming in Java. Some bits of it are nice, but it feels something like stripping paint with my fingernails.

      --
      Miri it is whil Linux ilast...
    14. Re:every year this happens... by jon3k · · Score: 1

      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?

      Ok, first off, it was half serious I'm sure.

      But, we're talking speed here. No one said those languages aren't nice, and have their place, but this article clearly states that Java is faster than C++ - which, quite frankly, is a load of bullshit.

      No one is going to argue that you can perform very large floating point calcuations faster in python, etc than in C. I mean, for god's sake, most (if not all) of those interperters are written in C/C++! You're just adding layers of complexity.

    15. Re:every year this happens... by Anonymous Coward · · Score: 0

      If by "the standard Java compiler" you mean javac .... uh, no, it doesn't do anything of the sort.

    16. Re:every year this happens... by Anonymous Coward · · Score: 0

      Unless you believe the first C++ compiler was written in C++.

      I don't, but since there are program source codes that are both legal C programs and legal C++ programs then conceivably the first C++ compiler could have been written in C++.

    17. Re:every year this happens... by JuliusRV · · Score: 1
      And how's that different from C++? Unless you believe the first C++ compiler was written in C++...

      Ehm. The first C++-compiler _was_ written in C++!

      http://www.research.att.com/~bs/bs_faq.html#bootst rapping
    18. Re:every year this happens... by RedWizzard · · Score: 1
      id's next game engine
      Carmack did seriously consider using Java for Quake 3 (though not for the rendering engine, presumably). In the end he decide to include a C interpreter instead, the reason being portability issues with Java.
    19. Re:every year this happens... by Aneurysm · · Score: 1

      I think id writes the actual 3d engines in C, and the other game code in C++ on top of that. I'm sure I saw some source code somewhere that suggested that. I find programming OOP in Java and C++ pretty similar, although Java has definitely to take the edge for me, as it is totally OOP. I prefer C++, but in a given environment I find myself using C++ without the OOP elements. In my eyes C++ is good for writing C code without all of the variable definition restrictions that C places (e.g. at the start of code blocks). In a totally OOP environment I think Java is generally easier

    20. Re:every year this happens... by TheLastUser · · Score: 1

      The article clearly shows that Java is only faster in some of the categories. Personally, I have rewritten C++ apps in Java and found that I had no trouble making them run faster in Java, not to mention the fact that it took me a month to duplicate 4 month's worth of C++ functionality.

      Its not impossible that Java would be faster at some things than C++, merely because the VM is written in C++. VM's have runtime advantages over languages like C++. A VM can optimize code based on how it is currently being used and where it is currently running, whereas C++ optimizations are a strictly compile-time exercise. If I create an app running on Linux/x86 and have it send an object to a Solaris/sparc machine, the object will optimize itself properly on both machines. If my application starts to use a particular segment of code heavilly then the VM can re-optimize for that execution pattern.

      Java takes a hit by requiring a VM, but, as this article shows, the hit isn't that big and the payoffs are probably worth it.

    21. Re:every year this happens... by Anonymous Coward · · Score: 0

      In the end he decide to include a C interpreter instead, the reason being portability issues with Java.

      Isn't Java supposedly the great white hope of write once, run anywhere? ;)

    22. Re:every year this happens... by xlv · · Score: 1

      And how's that different from C++? Unless you believe the first C++ compiler was written in C++...

      Ehm. The first C++-compiler _was_ written in C++!


      No, it was a set of C preprocessor macros and the underlying compiler was still a C compiler and not a C++ compiler per se.

    23. Re:every year this happens... by mcpkaaos · · Score: 1

      Right. And Woody Harrelson could kick Damon Wayans ass, too.

      --
      It goes from God, to Jerry, to me.
    24. Re:every year this happens... by mcpkaaos · · Score: 1

      Or not. I guess Woody Harrelson wasn't in that movie. Doh!

      --
      It goes from God, to Jerry, to me.
    25. Re:every year this happens... by dasmegabyte · · Score: 1

      No, that was written in Java too.

      Three years from now, the Just In Time compiler becomes so efficent that code is executed before it is written. A rift will open up in time, and the first Java compiler will land on the desktop of an unsuspecting Sun intern.

      --
      Hey freaks: now you're ju
    26. Re:every year this happens... by Anonymous Coward · · Score: 0

      Totally OOP, with primitives?

    27. Re:every year this happens... by Yrd · · Score: 1

      If you want to drop those variable restrictions use a C99 compiler, which appears to support such things.

      --
      Miri it is whil Linux ilast...
    28. Re:every year this happens... by j.bellone · · Score: 1

      Actually, id has written their engines in C since the beginning. Since the quake days, it's been called "QuakeC" if you decide to mod it. I'm not exactly sure why, just guessing they have a lot of types in the language macro'd off so that it's easier for cross-platform. The new engine, Doom 3 engine, is written in C++. I guess id finally decided to join the bandwagon ;p. There's an interview somewhere with Carmack explaining why he decided to make the jump to C++, I just don't remember the link.

      --
      I'm f#$king magic!
    29. Re:every year this happens... by Anonymous Coward · · Score: 0

      1. id used C and assembly for for Doom
      2. id used C and assembly for the Quake engine
      3. id developed a scripting language called "QuakeC" for writing quake.
      4. id used C for the Quake 2 engine and game DLLs
      5. id used C for the Quake 3 engine and game
      6. id developed a JIT compiled virtual machine for Quake 3
      7. Quake 3 allows QVMs (DLLs compiled for the virtual machine) or DLLs for writing game code.
      8. Doom 3 is written in C++.

    30. Re:every year this happens... by jon3k · · Score: 1

      Of course they have runtime advantages! They're emulated languages. Compile optimized C++ code on X platform and it will outperform java 99.9999% of the time. I can't believe we're even having this argument!

    31. Re:every year this happens... by TheLastUser · · Score: 1

      Obviously the tests were flawed, the tester was biased, and Microsoft was behind it all.

  23. Languages vs Compilers by Anonymous Coward · · Score: 5, Insightful

    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.

    1. Re:Languages vs Compilers by mrtoggles · · Score: 1

      not only that, but does someone who freely admits "I've never been very good at decoding GCC's error messages" have _any_ business comparing C++ to Java? To compare languages shouldn't it be assumed that you can understand them?

    2. Re:Languages vs Compilers by ms139us · · Score: 2, Funny

      Languages aren't "faster" or "slower"

      Thank God, finally someone understands! I was recently benchmarking Turtle Logo against some highly optimized Opteron-specific assembly code for an application that calculates PI to the 400,000th digit.

      I was surprised to see that Logo was slower, but I think I just didn't optimize it enough. I am tuning the Logo floating point code right now, and Logo should stomp the hell out of the assembly code "Real Soon Now."

    3. Re:Languages vs Compilers by Just+Some+Guy · · Score: 1
      Java and C++ are language.

      Not according to Sun:

      Java technology is a portfolio of products that are based on the power of networks and the idea that the same software should run on many different kinds of systems and devices.

      Java is the name of a language and a virtual machine, in much the same way that "Python" is both the name of a language and the interpreter that executes it. Now, if Java can eventually run on the Parrot VM, then you could make a pretty strong case that "Java" is more closely associated with the language than the VM. As a sysadmin, I'm currently more interested in "java" the application.

      --
      Dewey, what part of this looks like authorities should be involved?
    4. Re:Languages vs Compilers by Antique+Geekmeister · · Score: 1

      Yes, languages *are* faster or slower. The handling of stacks when doing subroutines, for example is a critical implementation detail of all languages, and the structures for handling arrays and pointers also matter a great deal. And many structural issues of the code itself encourage or discourage good coding practice, such as excessive generation of subroutines or poor handling of global versus local scoping of variables. C++ is *nasty* about global versus local handling of things: the template insanities required to protect your code from being unwoven elsewhere are pretty serious, and add a lot of unnecessary code.

      Do them well, and your code can be optimized within an inch of its life. Do them badly, and your code will never run at more than a fraction of its possible speed.

      But comparing Jave to C++ for speed is like comparing a runner with one leg to a runner with a moose strapped to his ass. Either may manage to complete the task, but they're both going to wind up slowed down a lot. If you want speed, for God's sake, write it in C!

    5. Re:Languages vs Compilers by Anonymous Coward · · Score: 0
      The point is that logo will whip your opteron code if you have a good logo implimentation and use an opteron emulator and debuger. Think about it.

      The language doesn't define the speed just as the comment you are mocking is explaining.

      Maybe you are too young to see the difference. Maybe you were reading to fast. Either way, a language is only a definition.

      You probably think multiplication is slower than addition as well. It's not. It's only slower when you are dealing with limited resources. That's an implimentation issue.

      This reminds me of people who confuse numbers with the representation of a number.

  24. -O3 by Anonymous Coward · · Score: 1, Insightful

    If you care about run-time speed when using gcc you compile with -O3.

    I'd like to see the benchmarks redone with this.

    1. Re:-O3 by Anonymous Coward · · Score: 1, Informative

      Don't forget strip -s

    2. Re:-O3 by Svennig · · Score: 1
      -O3 won't allways help you for optimisations. -03 generates huge binaries. This means that, often, the relevant sections of the program cannot be kept in the processor's cache and thus must be shifted out to ram resulting in slower execution.

      -Os, which seeks to minimise the size of generated files, often manages to keep more of the application in cache and this leads to an increase in execution speed.

      -O3 is really useful for people with 1 or 2mb of on-die cache processors. Who knows, in the future these may become abundant. It's swings and roundabouts; the benefits of one -O over another have been beaten to death.

      As an aside issue, the actual machine code generated by the JIT compiler isnt that great. Whats brilliant is that the compiler profiles in realtime, optimising the code for the input by heavily optimising hot branches and caching them. This often generates a 30% odd increase in performance.

    3. Re:-O3 by Anonymous Coward · · Score: 0

      -O3 can produce slower code than -O2. There's still much wrong with the benchmarks, bytecode is never faster than equivilent native code, even when using G++.

  25. Watch the flamefest unfold in realtime! by Anonymous Coward · · Score: 0

    This is gonna be mean.

  26. Re:my arse by kaffiene · · Score: 3, Funny

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

  27. Nice to hear... by twocoasttb · · Score: 4, Insightful

    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.

    1. Re:Nice to hear... by drew · · Score: 3, Funny

      I think about the PHP/PostgreSQL applications I write today and shudder when I imagine what how difficult it would be to have to develop web applications in Java...

      --
      If I don't put anything here, will anyone recognize me anymore?
    2. Re:Nice to hear... by dasmegabyte · · Score: 1

      Funny, I shudder when I think about PHP applications too...

      --
      Hey freaks: now you're ju
  28. Java is still more expensive by filesiteguy · · Score: 0, Offtopic

    ...but accordiing to the unbiased and objective Microsoft study, Java under Linux on a 3090 mainframe is still more expensive to run than NT Server 5 on a whitebox machine with dot net. What do they say to that? Hell, I'll stick with coding in whitespace. What do y'all think of this routine: K

  29. Re:Caught up with the speed, but still the ugliest by mark-t · · Score: 4, Informative
    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.

  30. A few points... by mindstrm · · Score: 5, Insightful

    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.

    1. Re:A few points... by leakingmemory · · Score: 1

      Maybe the real point is that Java does more optimizing where the real problem is inefficient programming?

    2. Re:A few points... by Anonymous Coward · · Score: 0

      The author is keen to put out flamebait.

      Comparing optimized JVMs to g++ using -O2 is indeed not a good thing.

      He should try it with the Intel C++ compiler.

    3. Re:A few points... by unoengborg · · Score: 1

      Code ode should not need to be optimized for a specific compiler. As long as programmer time is more expensive than faster hardware, code should be optimized for readability and maintanabilty not for speed, unless you program for very extreeme conditions.

      --
      God is REAL! Unless explicitly declared INTEGER
    4. Re:A few points... by kaffiene · · Score: 1

      Runtime optimisation. You can optimise some things at run time which cannot be optimised ahead of time (e.g. runtime constants)

    5. Re:A few points... by mindstrm · · Score: 1

      Perhaps not for a specific compiler, but for a specific language, YES.. there are right and wrong ways to implement an algorithm, and differences in implmenetation can have drastic effects on speed.

      You can't say "Just write it any way you want, and the compiler will figure out what you meant and optimize it".. it doesn't work that way.

    6. Re:A few points... by nairbv · · Score: 1

      There's a section at this link ("And In Theory: Maybe Java should be faster") about why it makes sense that java performs better than C++ in some situations: http://www.idiom.com/~zilla/Computer/javaCbenchmar k.html
      There are many things that java can do to optimize that C++ by it's nature just can't do. So many people make the assumption that java being faster than C++, as you say, "just doesn't make any sense." It does make sense.
      Yes there will *always* be some bias in any benchmark, but every language has its pluses and minuses. There are many cases where a well written java program will perform better than a C++ program, even if the C++ program is written really well (and vice versa).
      The third point at the link I reference, "Run time compilation," which he considers the least convincing, does apply to 90% of the code I write because I'm usually using java in web applications.

    7. Re:A few points... by Trillan · · Score: 4, Insightful

      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.

    8. Re:A few points... by maraist · · Score: 2, Insightful

      Except that in enterprise computing (as opposed to scientific computing), we are not interested in JUST throughput, but more often the time-to-shipment of the application, and the robustness of the code. Robust code is often abstracted or is littered with superfelous code (i.e. redundant checks for nullity).

      Code that is easy to read, easy to maintain is often not very performant, because you aren't allowed to make special-case optimizations at the code level, since they are often a nightmare for other's to interpret.

      In terms of efficient elegant code, it is trivial to use a hash table over a linked list in java (in fact, linked lists are harder to implement). Thus a LOT of java code uses such O(k) algorithms. On the other hand, in c it's relatively easier to use bitmaps than a hashed set, and thus c has less overhead for a common practice. But, as a consequence, bitmaps often have an upper-bound (no more than 32 entries) (yes, I know you can use bitmapped c structures). But a hash table is easier to read and harder to screw up than a boolean-logic bitmap, so it is often a better choice for "enterprise code".

      So my response is that it depends on how you define "efficient programming". Do you mean efficient execution (which really is optimized programming), or efficient writing and maintanance of code. I suspect you mean the former, but what you should mean is the latter.

      What's more, as far as a business man, you have to weigh the cost of development time v.s. performance of application. Well written non buggy, easily adaptable code requires little future man hours, and can take advantage of moore's law. If the software is successful, "scaleable" code can run on ever more expensive hardware (clustering). Highly optimized software may not be easily clusterable, or may not lend well to adaptations; each adaptation would require re-optimizing the code. The classic example here is Java's "Reflections", where a text configuration file is often used to link unrelated code together. I see this a lot in databases where we map new tables to code which may or may not be a proper fit.. The reflective configuration handles the remainder of the impedence mismatching. Note that you can do this in c as well, but it wouldn't be the fastest solution by far.

      --
      -Michael
    9. Re:A few points... by Cthefuture · · Score: 5, Interesting

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

      --
      The ratio of people to cake is too big
    10. Re:A few points... by Anonymous Coward · · Score: 0

      It makes perfect sense: he used g++.

      VC++ produces code that is up to 50% faster than g++'s code. So, by his numbers, C++ code produced from a real compiler is 20% faster than java.

      Java has always been about 20% slower than c++...

    11. Re:A few points... by GooberToo · · Score: 2, Insightful

      but there is no way I can accept that java is that much FASTER than properly done C++

      Well, bluntly, you need to better understand the technology so you can adjust your expectations. While I've only started looking at the code, it does appear that these benchmarks represent many ideal situations whereby java's hotspot technology can make many aggressive optimizations.

      These benchmarks, by no stretch of the imagination mean that Java is faster than C++. It does, however, clearly show that in ideal situations, hotspot can clearly make huge leaps in performance.

      Worth noting, psyco for python (a hot-spot "like" technology), also has ideal situations where it actually performs faster than c. Again, this is because it's able to more aggressively optimize in certain situations with more knowledge than the compiler had during compilation. Does this mean that, in whole, python+psyco is also faster than c? Of course not. But, it certainly does lend support to the notion that java and it's hot spot technology can not be dismissed out right, as I see many racing to do.

      The big question, which I currently do not have an answer to is, do these benchmarks have any meaning in the least, in the real world? If so, in what situations do they reflect?

      In stead of panicing about these results, let's take them for what they are, lick on a grain of salt whlie we're at it, and figure out if they mean anything in the real world. I suspect that they don't, but that's just my bias talking. In the mean time, I'm going to be looking at some code.

    12. Re:A few points... by Anonymous+Brave+Guy · · Score: 1

      I wrote another post recently, on a similar theme. In that case I was contrasting Perl and C, but the same arguments would apply here pretty much unchanged.

      That said, these benchmarks are still just as unrepresentative as they were the first time, still contain random and pointless differences, and still look like C++ written by a Java programmer (using new to create the objects in the methcall example is just weird in C++, for example). To be of any value in a language comparison, you'd need tests doing realistic tasks on a reasonably large scale with roughly equivalent algorithms; trivial code snippets like these wouldn't tell you anything except what you wanted to see in them anyway.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    13. Re:A few points... by larien · · Score: 1

      Addition to the above; when choosing your language/compiler etc, balance the costs of extra hardware to run the slower language versus the costs of programmers to program/debug the language. The balance these days is that hardware is comparitively cheap compared to programmers, so an easy to write language with quick deploy time is cheaper, even if it takes more hardware.

    14. Re:A few points... by Anonymous Coward · · Score: 0
      VC++ produces code that is up to 50% faster than g++'s code.
      Citation?
    15. Re:A few points... by Q+Who · · Score: 1

      <iostream> is not "extremely slow", use std::ios_base::sync_with_stdio(false), or a compiler with a decent Standard C++ Library.

    16. Re:A few points... by j3110 · · Score: 1

      I'm sorry you can't wrap your mind around dynamic runtime optimizations...

      But in any case, everything can be condensed to assembler, so why don't you just argue that he didn't use C++ to it's most optimum performance because he didn't do:

      void main() {
      asm {
      xor %ax, %ax
      }
      }

      Using C++ the way it's supposed to be (cout, etc) is not cheating. There are things I could do to optimize his Java examples, but usually you never have to, because it's fast enough.

      Another flawed arguement is: Java is written in C, it can only be as fast as C. That's a lie... Java runtime optimizes code with JIT for the target processor. It can inline functions at will. C can't do those things at runtime.

      I don't know what kind of funding your projects have, but I don't have the time to spend optimizing algorithms for the last 10%... especially when most of my code is IO bound. Java gets your job done quicker, and plenty fast enough without needing any third party libraries usually.

      --
      Karma Clown
  31. Could use a good analysis by GillBates0 · · Score: 5, Interesting
    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.

    --
    An Indian-American Hindu committed to non-violent thought/speech/action alarmed by the global explosion of radical Islam
    1. Re:Could use a good analysis by Anonymous Coward · · Score: 1, Insightful

      The JIT has run-time path information that g++ does not and can put parts of the hot path together so that they are the same page in cache. YEEEHAW

    2. Re:Could use a good analysis by Magnus+Pym · · Score: 2, Informative

      I agree with you. This does not match my experience at all. The Java programs I have used (especially anything with a GUI) have been bloated and much slower than programs in C++ that do 10 times as much. I would be curious to see if these benchmarks included things like opening windows, pulling down menus etc.

      Magnus.

    3. Re:Could use a good analysis by cduffy · · Score: 2, Insightful

      Well, yes, but the GUI issues are something completely different -- specifically, that Sun has no clue how to write a decent widget set, and insists on going either too far in one direction (AWT -- only supplying widgets available natively on every supported platform) or too far in another (Swing -- emulating every widget even on platforms where they're available natively).

      These benchmarks *didn't* include things like opening windows and so forth, and I think that's appropriate. Anyone who cares about writing a graphical Java app with decent performance should be using a different widget set anyhow, like IBM's SWT.

    4. Re:Could use a good analysis by gwernol · · Score: 1

      The results are very non-intuitive.

      Agreed. Of course, this doesn't mean they're wrong.

      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 believe the answer is this: statically compiled languages like C++ are limited in the range of optimizations they can perform - the optimizer knows the structure of the program (classes, objects etc.) but not how code segments are used at runtime.

      A language like Java is compiled at runtime. One of the things the JIT does is optimize the code path that runs most frequently (this is the "hotspot" capability in Sun's JVM) regardless of where that code lies within objects. Because the common execution path may cross object boundaries optimizing for that should in theory lead to better performance. The claim is that these runtime cross-object optimizations produce significant performance gains that more than cancel out the overhead of a JVM.

      Of course this will only work in certain cases, but it does have at least some theoretical appeal.

      --
      Sailing over the event horizon
    5. Re:Could use a good analysis by jfengel · · Score: 5, Interesting

      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.

    6. Re:Could use a good analysis by brunes69 · · Score: 1

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

      People often cite this as a downfall of Java, when it is in fact this virtualization that can make Java faster than C++, and in some cases, even faster than C.

      On the other hand, code paths that are never used do not get the same attention, and are thus not optimized as much. However, a code path that is never used is likely not as time critical; and you can always instruct the JVM to follow those paths and optimize them if you want.

      Modern JVMs re-compile and re-optimize bytecodes continuously during execution, until no significant gains are noticed by the optimizing compiler. The result of this is a program that gets faster and faster the longer you use it. The longer you use it, the more efficient the instructions, until you end up at a point where the bytecode is being interperted so efficiently that the only way to match it in terms of performance would be custom hand-coded assembly.

    7. Re:Could use a good analysis by Anonymous Coward · · Score: 0

      All many of the benchmarks really measure there is call overhead, including recursive one. And the Java JIT may do a better job of it, particularly if it does inlining tricks. It may be interesting to see how tree-ssa performs on this, or any gcc version with -funit-at-a-time.
      I bet playing with inlining heuristics can change performance quite abit, too.

      Some benchmarks also use I/O. To give decent performance for that in C++, one needs to disable the synchronization with C streams.

      Heck, the only realistic benchmark there is mmult. And well, the outcome there is very different from the headline.

    8. Re:Could use a good analysis by Unordained · · Score: 1

      Also, we need to remember there are issues related to C++ (the language) and C++ compilers, vs. Java (the language) and Java compilers/virtual machines. Is the Java language itself faster than C++?

      Here, the issue you brought up of identifying things that will not be true (formally) makes sense. That's thanks to the language. With JIT, Java now compiles for the platform it's on. That's overhead -- imagine all your apps requiring users to have GCC installed so it can compile them as you go, for the target platform. But you can also get platform-specific optimizations (not just compiling for the common denominator), and the run-time optimizations (if done correctly) seem useful too.

      Cross-platform compatibility, at this point, is more of an issue of writing good code, and shipping compilers for all platforms. Last I heard there were more platforms with a C/C++ compiler than with Java compilers/virtual machines. But most code isn't written to be cross-platform (people get lazy, or have a schedule.)

      Seems now the difference is mostly going to be in the delivery part, not the coding part. Both have standard libraries, both can be optimized, they're similar anyway ... It's then all about weighing costs: start-up time (I don't want to fire up a JVM when I run "ls") and run time (I don't need run-time optimization when there isn't much in the way of loops that can be optimized.)

    9. Re:Could use a good analysis by gwernol · · Score: 1

      Well, yes, but the GUI issues are something completely different -- specifically, that Sun has no clue how to write a decent widget set, and insists on going either too far in one direction (AWT -- only supplying widgets available natively on every supported platform) or too far in another (Swing -- emulating every widget even on platforms where they're available natively).

      I have to disagree. I've worked on both a commercial OS-level widget set and inside the Java/Swing widget source code. Swing widgets are actualy pretty well architected and coded, as widget sets go.

      The real performance problem is that Swing (and all the J2SE libraries) are essentially monolothic. Even a primitive "Hello world" requires you to load pretty much all the runtime library into memory. This leads to horrible startup times for Swing apps, and often forces systems deep into swap. This really, really doesn't help performance.

      On the server-side this is actually a good attribute - since you typically have machines with lots of memory so everything can live in real memory and all functionality is available.

      But Java/Swing apps will never be acceptable for desktop applications because they can't partially load the Java libraries. This is an architectural flaw because the components are intrinsically intertwined. Decoupling the various units of functionality is theoretically possible but in practice would be an enormous undertaking that I don't believe Sun is interested in.

      --
      Sailing over the event horizon
    10. Re:Could use a good analysis by Halfbaked+Plan · · Score: 1

      I'm not sure many businesses are ready to implement 'recompiled all the time' code that optimizes and retunes itself while running. How does code like that get verified and validated for critical applications? It sounds like a series of disasters in production waiting to happen.

      --
      resigned
    11. Re:Could use a good analysis by Anonymous Coward · · Score: 0

      Are you kidding? What do you think all those mission critical J2EE applications are doing? They're running on runtime optimized VM's like HotSpot.

      There is no such thing as static code that doesn't change, even if you program in assembler. The chips are doing fancy out-of-order execution. The OS is paging, and inserting compatibility shims, relocation your stuff. All this stuff needs testing from the chips to the OS to the VM's, but it works.

      This technology is mature and in production.

    12. Re:Could use a good analysis by Anonymous Coward · · Score: 0

      No no no no no! The Java VM in terms of Garbage Collection and runtime compilation should be considered in last place as far as interpreted languages go. It's really the worst example you could have mentioned.

      Microsoft's C# (yes it runs on Linux, so dont get your panties in a bunch) has totally trumped Java when it comes to actual execution. Their garbage collection is FLAWLESS and unnoticable. Java on the other hand, does require a level of understanding in terms of what is to be collected and what isnt. Many large java programs, such as Borland JBuilder are examples of poor java programming as they are just that: Large. It is not uncommon to see JBuilder take huge amounts of memory or sit there GC'ing itself to death. C# programs have this great tendancy to run quickly, GC without any pain, and have no stinky side effects like eating up most of your system resources.

      Sun's Java wasnt even allowed on the Mars landers, which use VMWare's compiled, embedded Java. Luckily that version is a tad more stable!

      I used to be the biggest Java advocate. I have written several company-wide applications in Java, which are still in use today. I do like the language, and its simplicity, but its got a LONG way to go to catch up again to C# as a consultant's best rapid development friend.

    13. Re:Could use a good analysis by Paul+Lamere · · Score: 2, Informative
      One of the papers cited on the page is the FreeTTS FreeTTS - A Performance Case Study a paper written by the speech team here at Sun's Research Labs.

      This paper describes the performance issues we encountered when developing FreeTTS. I think it is a pretty good representation of the issues involved in developing a high-performance Java application along with a comparision between a Java and a native-C version of the same application. This paper describes how we ported a native-C synthesizer (Flite) to Java (FreeTTS) and how were able to get better performance from our engine.

      This is not a toy application but a real application that performs well in a domain where performance really matters.

    14. Re:Could use a good analysis by grotgrot · · Score: 1

      For even more fun, you can run a C++ program under a JIT. Although it sounds absurd, HP's Dynamo got around 20% performance improvement on binaries compiled on -O2 and even more on those compiled with -O4!

    15. Re:Could use a good analysis by Halfbaked+Plan · · Score: 1

      Pardon me, but some of us code in Assembler without an OS under it to hold hands with. Plus we write assembly code for chips that don't do fancy out-of-order execution.

      Granted, I'm drifting significantly off the topic of 'business apps.'

      --
      resigned
    16. Re:Could use a good analysis by nikster · · Score: 1

      You can even start spreading loop cycles over multiple CPUs, but I'm pretty certain that the present JVMs aren't that smart.

      the JIT could also recognize code that can be vectorized and take advantage of SSI/AltiVec automatically.

      That would make Java blazingly fast and incredibly efficient in some applications. Imagine getting SSI/AltiVec optimization for free! That would be a huge value for programmers right there.

    17. Re:Could use a good analysis by Anonymous Coward · · Score: 0

      Sun engineers publish an article in a sun publication extolling the virtues of a sun product. Wow, what a shocker.

    18. Re:Could use a good analysis by jfengel · · Score: 1

      One of the sweet things about Linux is that you can assume that you're going to compile the program on the individual computer, and optimize it for the precise CPU and chipset you're working with. That gets you the best of both worlds: highly optimized code for each individual system, at a cost of making installation a nightmare.

      You don't get Java's dynamic runtime optimizations, but as sibling posts have pointed out, they may be far more beneficial in theory than practice.

      I personally write in Java because of its speed, not at run-time but at development-time. Because I don't have to have meetings with individual developers and hammer out an agreement about freeing each individual data structure's memory, and because I don't spend months tracking down fandango-on-core errors, the time it takes for the program to run the first time is (three months to develop plus 3 seconds to start the JVM plus 100 milliseconds to run it) versus (a year to write plus 10 milliseconds to run).

      But that's just the development environment I work in and the circumstances I'm trying to optimize; yours may be different. Many slashdotters work individually, which means that they have better knowledge of the program as a whole and therefore certain memory problems don't happen.

      I don't worry about questions like "Is language X faster than language Y?" I try to choose the best language for whatever task it is at hand, and I've got a lot of them to choose from.

  32. Re:Caught up with the speed, but still the ugliest by saden1 · · Score: 4, Insightful

    I’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’t be taken seriously.

    --

    -----
    One is born into aristocracy, but mediocrity can only be achieved through hard work.
  33. That just means... by SuperKendall · · Score: 2, Interesting

    You were running Swing with the Windows L&F.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  34. Re:my arse by Anonymous Coward · · Score: 0

    what i want to know is how did they run the benchmark without the java virtual machine.

    i'm sure "command not found" is worlds faster then a loop in C++.

  35. New benchmarks show... by Anonymous Coward · · Score: 0
    Java is now faster than machine code!

    But seriously...this is entirely dependent on code design. Java people and C++ people are terrible at it (else how could they like these languages?). And I'm not about to RTFC to find out how they cooked this one up.

  36. the more people... by bsDaemon · · Score: 1

    that know about present-day java performance, the more people will use java. is that really "the better?"

  37. Riiiiiiight by SmallFurryCreature · · Score: 1, Flamebait
    I only know one thing. That the 2 java programs I use, freenet and azureus, are horrible monsters, nice ideas but badly implemented.

    Compared to similar applications written in real languages (meaning any language that is not java) they are crash prone, give idiotic debug statements, suck up memory and easily get the "too many open files" error on linux.

    I guess this is like "Windows nowadays is very stable" bit. You can show all the benchmarks and tests but I will let my daily experience be the judge and use reports such as this as the toilet paper it is.

    To be fair, freenet does work on linux and windows as does Azureus. This is for me the only selling point.

    Perhaps java is faster then C++, it is hard for me too judge. But until Java developers start writing better programs, Sun makes sure Java is really cross platform, and games (the ultimated performance applications) start being written in java I will file this with all the other reports on how java will take over the world and is the best, fastest, easiest.

    --

    MMO Quests are like orgasms:

    You may solo them, I prefer them in a group.

    1. Re:Riiiiiiight by Texas+Consultant · · Score: 0

      Or defining "stable" (sensu Windows) by the usage pattern: "When I run Microsoft Office and IE only, it is very stable..." Then again, most users don't need Linux "stable" either. They need GEOS

    2. Re:Riiiiiiight by Anonymous Coward · · Score: 0

      I only know one thing. That the 2 java programs I use, freenet and azureus, are horrible monsters, nice ideas but badly implemented.

      Heh, I knew the very same thing (well, only for freenet) few years ago. Then I assumed that it was simply because java sucks but later accepted a job as a java programmer anyway. Now, to my surprise my program didn't become one of the monsters. In fact it does few things a magnitude better than several of its competitors.
      My only conclusion is that java people in general fail to respect the following inequality: Idiomatic OO != fast.

    3. Re:Riiiiiiight by El+Neepo · · Score: 1

      To be fair, Azureus is a horribly coded application. I'm currently working on a clone of it using a different core. Core is snark and I'm calling my app, Comrade.

      I should update the CVS sooner or later.

    4. Re:Riiiiiiight by l33t-gu3lph1t3 · · Score: 2, Informative

      Windows nowadays *is* very stable. I've been working as a systems administrator over Windows NT, 2000, XP, and 2003 Systems for about 2 years now (obviously I haven't spent that much time on 2003...) and you know what? Except for one really screwy problem that later turned out to be memory-related, I have never had stability problems with those flavours of MS Windows.

      Ok that's not entirely true. I've seen Windows stability problems. They were the result of user stupidity like truckloads of spyware and hard disks with no space left.

      And as far as "idiotic debug statements" go, GCC holds the frikkin crown for those. When java compiler or runtime crashes, it tells you more about what went wrong than C++ does...perhaps the reason you see amateurish java programs is that the amateurs and programming students are switching from C++ (a language no one should use unless they're supremely gifted as a programmer) to Java (a language that saves them from their own stupidity).

      --
      ------- "From bored to fanboy in 3.8 asian girls" ----------
  38. This might be funny, but it isn't informative. by John+Harrison · · Score: 1

    I'll explain the joke for the moderators: He is incurring the overhead of launching the JVM, which is significant. In fact, all this tests is that invocation overhead and nothing else.

  39. Expert results by otterpop81 · · Score: 5, Insightful
    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.

    1. Re:Expert results by Xugumad · · Score: 4, Interesting

      Also, a quote from the article:

      "I was sick of hearing people say Java was slow, when I know it's pretty fast"

      Nice, unbiased viewpoint there...

    2. Re:Expert results by danharan · · Score: 1
      That's Great! I can't figure out GCC's error messages, but I offer definitive proof that Java is faster than C++. Nice.
      If I can compile it in Java, but it takes me hours to understand a cryptic error messages, the least I can say is Java is faster to write :)

      I really don't care whether C++ is faster than Java to execute, as long as my apps are fast enough.
      --
      Information: "I want to be anthropomorphized"
    3. Re:Expert results by glwtta · · Score: 1
      "I was sick of hearing people say Java was slow, when I know it's pretty fast"
      Nice, unbiased viewpoint there...

      A preconception does not imply bias. It's virtually impossible for anyone to go into such a reivew and not have any opinions about the products they are testing beforehand. It's how they handle the results that counts, not what prompts them to do the study in the first place.

      And I definitely agree with him, the unsubstantiated claim of the unqualified "slow" criticism of java is long outdated.

      --
      sic transit gloria mundi
    4. Re:Expert results by drew · · Score: 2, Funny

      you didn't even have to go that far to see his bias... just take a look at the title:

      The Java is Faster than C++ and C++ Sucks Unbiased Benchmark

      --
      If I don't put anything here, will anyone recognize me anymore?
    5. Re:Expert results by Anonymous Coward · · Score: 0

      There's a difference between being biased and having an opinion.

    6. Re:Expert results by fijimf · · Score: 1

      I don't believe he claims definitive proof. You only have to read a few of the posts in this thread to understand his mindset -- I imagine he was annoyed by C++ chauvinists dismissing Java as orders of magintude worse in performance than C++. It simply isn't.

      Over the past year I've been in more than one interview where C++ experts (and these were talented guys) just had no idea about where Java was. It was as if they had written a 'Hello World' applet in 1997 or maybe dabbled with Visual J++ a few years later and wrote the language off permanently as a toy language.

      It used to bother me. But now I realize that they're the ones with the problem.

  40. Re:my arse by Anonymous Coward · · Score: 1

    In terms of speed it is un debatable that C is faster than Java because the jvm is written in C and execute bytecode which no matter how intelligently refactored will create one more level of indirection that lets pure C be faster.

  41. Re:This doesn't make any sense... by Ianoo · · Score: 4, Informative

    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.

  42. Re:my arse by Anonymous Coward · · Score: 0

    Looks like you haven't changed a bit!

  43. Largest Prime by Boyceterous · · Score: 0, Flamebait

    ever discovered with Java: 1 (still waiting on that next one, I guess it's garbage-collecting) Can we build a grid-based garbage collector?

    1. Re:Largest Prime by Anonymous Coward · · Score: 0

      That's quite a feat, given that prime numbers must be, by definition, natural numbers greater than one.

    2. Re:Largest Prime by jfengel · · Score: 2, Informative

      I know you're joking to make a point, but you do realize that 1 isn't prime, right? That's not just a matter of arbitrary definitions; a lot of theorems that apply to primes don't apply to 1.

  44. I don't actually care hugely about performance by Omnifarious · · Score: 5, Interesting

    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.

    1. Re:I don't actually care hugely about performance by Bullet-Dodger · · Score: 3, Interesting
      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.

      Have you looked at Objective-C? I'm not an expert, but it sounds just like what you describe. As a downside though, I'm not sure how well supported it is on non-OS-X platforms.

    2. Re:I don't actually care hugely about performance by deputydink · · Score: 1
      Java doesn't play well with others, and it was seemingly designed not to.


      Are you sure?

    3. Re:I don't actually care hugely about performance by Anonymous Coward · · Score: 1, Interesting

      Do you care that C++ is the worst implementation of object-oriented programming ever? Do you care that it's hard to read C++ code and maintain large C++ projects?

      Do you care that you have to start a mini-OS when you use Python? It even has its own command-line. (I like Python, by the way, for scripting. I'm just sayings is all)

    4. Re:I don't actually care hugely about performance by r.jimenezz · · Score: 1
      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.

      Try Googling for "Real Time Specification for Java". It sort of addresses everything in this quote except for the generic constructs (those are addressed by plain ol' J2SE in the upcoming 1.5 release).

      :)

      --
      The revolution will not be televised.
    5. Re:I don't actually care hugely about performance by andy55 · · Score: 1

      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.

      Objective-C is really impressive with the only shortcoming that there's no well-supprted Obj-C compiler that tagets x86 (that I know of). As I share with others, Obj-C is best described as taking the performance and power of C/C++ with all the safety and language correctness/elegance of java.

      I'm a vet C and C++ guy, and I swear by metrowerks codewarrior (its IDE and its x86 and PPC compilers). It'll be a big day if/when metrowerks makes a Objective-C compiler that targets x86 (for Win32).

    6. Re:I don't actually care hugely about performance by pHDNgell · · Score: 1

      there's no well-supprted Obj-C compiler that tagets x86 (that I know of).

      gcc's been The objective C compiler for as long as I've known about it.

      --
      -- The world is watching America, and America is watching TV.
    7. Re:I don't actually care hugely about performance by Xetrov · · Score: 2, Informative

      Converting objc -> c is trivial -- There are a number of objc -> c converters.

      Actually I think that might be how most of the compilers actually work :)

      So if you like Objective-C and would rather code in it... you can!

    8. Re:I don't actually care hugely about performance by Anonymous Coward · · Score: 0

      I care that Java is an inconvenient pain to develop in and use.

      How so?

      I care that the type system is too anemic to support some of the more powerful generic programming constructs.

      That should change with JDK 1.5

      Java doesn't play well with others, and it was seemingly designed not to.

      What do you mean by that? Btw, I do agree with your statement that Python is quicker to develop in.

    9. Re:I don't actually care hugely about performance by Anonymous Coward · · Score: 0

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

      What do you want ? C++ has a C-like memory model. it has inheritance and also supports polymorphic concepts. The generic programming capabilities are so powerful, that the C++ community is gleefully looking at it right now, totally amazed by what is possible ( for an eye-opener, read Modern C++ Desing by Alexandrescu). I really wonder where your problem is ? Syntax ? Look at C# generics, even they are imitating the syntactic style of C++ templates (but they fail on functionality). The C++ guys are no hotshots. Most changes end extensions only make it into the standard after a few people that are smarter and cooler than you and i combined, approve it. In these buzzword driven days, C++ may seem to be "slow-moving". Thats fine with me. It guarantees, that C++ will be usable in the years to come.

    10. Re:I don't actually care hugely about performance by locutus2k · · Score: 1

      Most true developers care at least to some degree about performance. If you software is slow, and bulky, who is going to buy/use it? At the risk of becoming flaimbait, after reading that first line of your reply you have set the tone as someone who doesn't appear to know what he/she is talking about. I did finish reading your post, but as a thought, you might consider what you are going to say before you say it.

    11. Re:I don't actually care hugely about performance by Omnifarious · · Score: 1

      That's what the qualifier 'hugely' was for. Performance is important, to a degree. It's not like I'd be happy to use a language that was consistently 50% or even 75% the speed of another.

      But, you're probably right. I tend to react overly strongly to pro-Java stuff because I don't actually think the language is really awful. I just think it's overhyped and overused, and that a lot of its supposed benefits are fictitious.

    12. Re:I don't actually care hugely about performance by locutus2k · · Score: 1

      You're exactly right. java is overhyped, and stuffed into places where it may not be the right tool. I personally have a deep hatred of Java, but am willing to give it a change to improve, and hope one day it will become as useful as the press says it is.

    13. Re:I don't actually care hugely about performance by Anonymous Coward · · Score: 0

      Really? With reflection, how do I determine the parameterized type of the elements in a collection? I don't. How do I keep someone from adding an item of the wrong type to the collection with reflection? I don't. How to I avoid performing expensive casts at runtime on my parameterized collection? I don't.

    14. Re:I don't actually care hugely about performance by Anonymous Coward · · Score: 0

      1. GCC contains an Objective-C compiler (added by NeXT when the FSF threatened to rain fire on them)
      2. POC (Portable Object Compiler) is an Objective-C to C preprocessor and runtime library.
      3. Objective-C does not have the performance of either C or C++. It can only have the speed of C if you don't use any of the extensions to C, because its string-based message runtime is several times slower than caling a function.
      4. It does not have any uniform mechanism for generic programming, so it can hardly fit the bill of the grandparent.

  45. Re:Caught up with the speed, but still the ugliest by C.+E.+Sum · · Score: 3, Informative

    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

    --
    -- Have you ever imagined a world with no hypothetical situations?
  46. Sorry, yes by Anonymous Coward · · Score: 1, Informative

    This means nothing.

    That is the most typical benchmark of somebody who doesn't know anything about compiler optimization.

    This is almost truly a mark on the compiler making an optimization in one case where the Java compiler doesn't. Assigning to an unused variable is a useless operation. A decent compiler removes the assignment, then notices an empty loop, then removes the loop.

    Not to mention, your double-click takes into account the entire VM initialization, which greatly, greatly outweighs the test itself, rendering the test useless on that account as well.

    So you end up benchmarking the entire VM initialization with a NOP. Gee, wonder which one's going to win?

    This is why benchmarks are hard. This is why the SpecINT benchmarks are notoriously bad as they (at least were) easy to optimize against.

  47. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 1, Informative

    By the sounds of it you have no idea what a good GUI is. Skins and themes do not a pretty UI make.

  48. Java vs. C++ by sameerdesai · · Score: 1

    We used to simulate our computer architecture projects in our graduate studies and often noticed java code to be very very slower than C++. Even the superscalar processor code is written in C++. Ultimately I feel whatever these tests show people find C++ easier and faster to develop good simulation software and overall much better.

  49. Flawed Test by Emperor+Shaddam+IV · · Score: 3, Insightful

    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.

  50. Re:Gentoo? by Anonymous Coward · · Score: 0

    i use debian, probably the same way it effects me, but years later.

  51. IL2 Sturmovik is Java by Anonymous Coward · · Score: 0

    IL2 Sturmovik is mostly Java. IIRC, only the rendering itself was done in native code for performance. With the advent of JOGL, even that can probably be done well in Java.

  52. Some problems I had using Java by Anonymous Coward · · Score: 2, Funny

    I don't want to start a holy war here, but what is the deal with you Java fanatics? I've been sitting here at my freelance gig in front of a Java program (running on a PIII 800 w/512 Megs of RAM) for about 20 minutes now while it attempts to copy a 17 Meg file from one folder on the hard drive to another folder. 20 minutes. At home, running an equivalent Visual Basic program on my Pentium Pro 200 with NT 4, which by all standards should be a lot slower than this Java program, the same operation would take about 2 minutes. If that. In addition, while it is running, Netscape will not work. And everything else has ground to a halt. Even jEdit Lite is straining to keep up as I type this.

    I won't bore you with the laundry list of other problems that I've encountered while working on various Java programs, but suffice it to say there have been many, not the least of which is I've never seen a Java program that has run faster than its VB counterpart, despite Java's faster runtime system. My 486/66 with 8 megs of ram runs VB programs faster than this 800 mhz machine runs Java at times. From a productivity standpoint, I don't get how people can claim that Java is a "superior" language.

    Java addicts, flame me if you'd like, but I'd rather hear some intelligent reasons why anyone would choose to use a Java over other faster, cheaper, more stable systems.

    1. Re:Some problems I had using Java by ky11x · · Score: 2, Funny

      You, sir, are inspired. I applaud this wonderful transformation of the Mac troll into a Java troll. I'm sitting over here laughing so hard my nose hurts.

    2. Re:Some problems I had using Java by Anonymous Coward · · Score: 0

      One poorly written Java program to copy files and you give up on it (I hear the Windows Explorer works better for that). Bore me with the laundry list of Java problems. How can there be a discussion without particulars. I will never choose Java over other faster, cheaper, more stable systems. I use Java all the time, in projects where it is appropriate. It increases productivity.

    3. Re:Some problems I had using Java by KZigurs · · Score: 1
      Java addicts, flame me if you'd like, but I'd rather hear some intelligent reasons why anyone would choose to use a Java over other faster, cheaper, more stable systems.
      Like VB, for example? Ahh, I won't even try to explain that noone tries to use java GUI anymore, but take it away and suddenly you see damn stable, fast and maintainable language that is simple to code in as well. And, in my opinion, way more logical than VB.
  53. disable JS to get past his redirect :) by drgroove · · Score: 1

    The Great Computer Language Shootout
    Back to the Language Shootout
    Back to Doug's Homepage
    [NEWS] [Editorial] [FAQ] [Methodology] [Performance Tips] [Download] [Activity Log] [Acknowledgements] [Scorecard] [Slash-Holed] [Rules for Benchmark Writers] [Conclusion] [Todo]
    Hi, the shootout is an unfinished project. I've decided to discontinue updates to it for now while I work on some other things. Thanks for everyone's help.
    [ 30 Language Implementations, 25 Benchmark Tests, 750 Total Possible Programs, 632 Written ]
    Here's a list of which solutions have/have not been implemented.
    The Benchmark Tests
    Ackermann's Function
    Array Access
    Count Lines/Words/Chars
    Echo Client/Server
    Exception Mechanisms
    Fibonacci Numbers
    Hash (Associative Array) Access
    Hashes, Part II
    Heapsort
    Hello World
    List Operations
    Matrix Multiplication
    Method Calls
    Nested Loops
    Object Instantiation
    Producer/Consumer Threads
    Random Number Generator
    Regular Expression Matching
    Reverse a File
    Sieve of Eratosthenes
    Spell Checker
    Statistical Moments
    String Concatenation
    Sum a Column of Integers
    Word Frequency Count
    (Not all languages are tested in every benchmark)
    Other Language Comparisons
    Creating Binary Extensions
    (These are non-performance language comparisons)

    A benchmark comparison of a number of programming languages.
    Note: If you want a copy of the shootout, please get it from the Download Page, but please do not hammer my server requesting every page. The shootout tarball is updated nightly. Thanks.
    Intro

    When I started this project, my goal was to compare all the major scripting languages. Then I started adding in some compiled languages for comparison ... and it's still growing with no end in sight (so be sure to read the NEWS). I'm doing it so that I can learn about new languages, compare them in various (possibly meaningless) ways, and most importantly, have some fun.

    Someday, maybe, the results I present might even be meaningful, but please take the current results with a grain of salt. You might get different results on a different OS, on different hardware, with newer releases of the languages, or even from run to run of the same test. You might even find that I have horrible bugs in my testing method.

    This is very much a work in progress, as it evolves I may add, change or remove languages, tests, or solutions. Some solutions as currently presented are unoptimized, and may be optimized in the future (if I can do it myself or if someone contributes a better solution).

    Disclaimer No. 1: I'm just a beginner in many of these languages, so if you can help me improve any of the solutions, please drop me an email. Thanks.

    Disclaimer No. 2: These pages are provided for novelty purposes only. Any other use voids the manufacturer's warranty. Do not mix with alchohol. Some contents may consist of recycled materials.

    Disclaimer No. 3: ditto.

    Disclaimer No. 4: Please read the pages on Methodology, the FAQ, and my Conclusion before you flame.

    By the way, the word Great in the title refers to quantity, not quality (I will let the reader judge that). I saw a need for a more comprehensive language comparison than what I could find out on the Net, and you are reading my solution. I wanted to see a comparison of more languages doing more tests, and with (hopefully) the participation of more people.

    Aldo Calpini has put a huge amount of work into porting my shootout to Microsoft Windows. He even includes some new languages and some commercial compilers that run on Windows. Please click here to check it out. (Please note that there may be some differences in his port. It is really a separate, derivative work). Many thanks to Aldo!

    The Languages
    Language Imple-
    mentation
    (local summary) Version
    (Official Homepage)
    1. Awk gawk GNU Awk 3.0.6
    2. Awk maw

  54. Game engines use it for behaviour logic... by SuperKendall · · Score: 1

    There's at least one well-known game, something about Vampires, for the PC that used Java for the behavior engine.

    As for the 3D engine, of course you want that optimized and you'd proably not want ot use Java - though you could if Java 3D had been improved. I odn't think that every was a well defined spec.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
    1. Re:Game engines use it for behaviour logic... by Anonymous Coward · · Score: 0

      there's also Dungeon Master Java

  55. Maybe on Fantasy Island by boy_afraid · · Score: 1

    Tatoo: Boss, who's that?

    Mr. Rourke: We have here Mr. Java. He has come here to live out his fantasy of being the fastest programming language around. Even faster than C++, but he will discover much more.

    Tatoo: What will he disover, Boss?

    Mr. Rourke: He will discover that he is in fact so slow that the only women he will be able to satisfy are the Granola PETA Vegan lovers that plague the Java world.

    ---
    Everyone takes thier drinks, including Tatoo and Mr. Rouke
    ---

    Mr. Rourke: I welcome you all to FAN-tasy Island! And may you all get it shoved up the ass!

  56. Only one? by Matthew+Weigel · · Score: 1, Flamebait

    Am I the only one who thinks michael uses Slashdot to post stupid crap that just supports his own uninformed bias?

    --
    --Matthew
    1. Re:Only one? by Matthew+Weigel · · Score: 1

      whoops, forgot to add: and tries to start flamewars (i.e., posts things that if they were comments, would be -1, Flamebait)?

      --
      --Matthew
    2. Re:Only one? by Anonymous Coward · · Score: 0

      No, there's also the monkey up your butt.

  57. One example of why the tests are BS by mypalmike · · Score: 5, Insightful

    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.

    -_-_-

    --
    There are 0x40000000 types of people: those who understand 32-bit IEEE 754 floating point, and those who don't.
    1. Re:One example of why the tests are BS by Anonymous Coward · · Score: 0

      Eliminating one malloc/free call will save an insignificant amount of time. It won't significantly affect performance.

      Slashdot pundits are BS.

    2. Re:One example of why the tests are BS by Sebastopol · · Score: 1

      Don't think so. Allocation and printout are insignificant compared to the inner loop functions.

      --
      https://www.accountkiller.com/removal-requested
    3. Re:One example of why the tests are BS by andy55 · · Score: 2, Informative
      Why allocate and deallocate an object within the scope of a function?

      You would do it if you need a scrap object only sometimes (and didn't want to pay the overhead penalty of instantiating it every time the proc got called). Here's an example:


      void foo() {
      ...
      if ( SomeRareCondition() ) {
      AReallyNastyObject* temp = new AReallyNastyObject;
      ...
      delete temp;
      }
      ...
      }

    4. Re:One example of why the tests are BS by icc · · Score: 1

      This benchmark isn't useful. How can someone who can't write decent C++ and/or Java code try to make a performance benchmark and expect accurate results?

    5. Re:One example of why the tests are BS by Anonymous Coward · · Score: 0

      You would do it if you need a scrap object only sometimes (and didn't want to pay the overhead penalty of instantiating it every time the proc got called). Here's an example:

      void foo() { ...
      if ( SomeRareCondition() ) {

      AReallyNastyObject* temp = new AReallyNastyObject; ...
      delete temp;

      } ...

      }


      You didn't understand what he was saying. He was talking about allocating something on the heap when you could allocate it on the stack. Your code is making the same mistake because it should instead declare the object on the stack, like this:

      AReallyNastyObject temp;

      Look, no delete required, and it's faster, too.

    6. Re:One example of why the tests are BS by mypalmike · · Score: 1

      Hmm.. Didn't realize the tests were run with n=1000000000. Doh. Still, in a real program, the lack of stack objects in Java can really affect performance of typical programs.

      How, then, can Java out-methcall C++ by an order of magnitude?

      --
      There are 0x40000000 types of people: those who understand 32-bit IEEE 754 floating point, and those who don't.
    7. Re:One example of why the tests are BS by Anonymous Coward · · Score: 0

      The reason it is slow is actually the passing back of either an object or an object reference as a result of the activate() function, and then calling the value function from that. Much quicker would be to just return the result of the toggle.

      I take it this is supposed to be testing the speed of method calls, but calling two methods per loop will skew the results by up to a factor of 2.

    8. Re:One example of why the tests are BS by halosfan · · Score: 2, Interesting

      The point he's making is that the C++ code is poorly written, and that might well affect benchmarking.

      Also, if the activate function is virtual (no way to avoid it in Java), this is a runtime vtable lookup in the loop, whereas for a statically allocated object the address of the function would have been fixed at runtime. Granted, the cost is probably negligible to that of activate's implementation, but (a) it's impossible to know without actually profiling the code, and (b) the activate()'s implementation is likely to be as poorly written as the code that calls it.

      Of course, all of this implies I was too lazy to actually look at the activate()'s code...this is Slashdot after all...

      --
      My only problem with Microsoft is the severity of bugs in their software.
    9. Re:One example of why the tests are BS by rjh · · Score: 1
      That, and using cout instead of printf, are probably why this is slower than the "equivalent" Java.
      Apparently, you're unaware that one of the major benefits of C++ iostreams over C-style IO is iostreams have better performance.

      Nor is the allocation/deallocation going to be a killer. The inner loop dominates, and the inner loop has to look up the method via vtable. Pointers to objects are slower than direct object calls. I wonder how the metric would change if the C++ code was written with this in mind.
    10. Re:One example of why the tests are BS by Anonymous Coward · · Score: 0
      Actually,
      void foo() {
      ...
      if ( SomeRareCondition() ) {

      AReallyNastyObject temp;
      ...
      }
      ...
      }
      would produce the same effect. RTFC++M.
    11. Re:One example of why the tests are BS by Anonymous Coward · · Score: 1, Insightful

      How is this Informative ? An object in C++ is only constructed when the code flow reaches the point where the variable is defined. So if you put a stack object inside that if, it only gets built inside that branch, and you have the benefit of skipping it for the common cases, while still avoiding the heap.

    12. Re:One example of why the tests are BS by mypalmike · · Score: 1

      C++ iostreams are built on top of C io functions, no?

      The last time I benchmarked cout was a while back, so things might have changed, but they were ridiculously slow compared with straight C, at least in the libraries I was using.

      --
      There are 0x40000000 types of people: those who understand 32-bit IEEE 754 floating point, and those who don't.
    13. Re:One example of why the tests are BS by Bloater · · Score: 3, Informative

      The cout is done twice, and the new and delete are each done only once. They are not the reason for the poor performance.

      The problem is that g++ probably does not optimise it all inline, whereas the particular java VM he has chosen to use probably does.

      Although defining the Toggle variables with auto storage class may give g++ the hint it needs to realise this.

      Additionally, the activate method is declared to be virtual, this shouldn't be a problem, except that it may further hide the optimisation opportunity from g++. Note that the description of the test does not stipulate that it is testing virtual methods.

    14. Re:One example of why the tests are BS by Craig+Davison · · Score: 1
      You could declare temp on the stack anywhere within your if (SomeRareCondition()) block.

      A more common reason you would use new/delete for a single object like that is if you wanted to control exactly when its constructor and destructor were called. It might also be too big to fit on the stack because, for example, it has huge arrays as members.

    15. Re:One example of why the tests are BS by TummyX · · Score: 1


      Also, if the activate function is virtual (no way to avoid it in Java).


      Modern JVMs can actually inline many virtual method calls.

    16. Re:One example of why the tests are BS by Anonymous Coward · · Score: 0

      Yeah, I had a program with lots of byte output, and printf() simply wiped the floor with cout. Sounds like sometime to look at again and add to my webpage.

    17. Re:One example of why the tests are BS by Anonymous Coward · · Score: 0

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

      OMG. You really don't know anything about writing fast C or C++ code, do you? Why on Earth would you use printf() if you were interested in performance? The code sample prints fucking HARD-CODED STRINGS, so why in the hell would you use printf? Un-fucking-believable. You're an idiot...

    18. Re:One example of why the tests are BS by rjh · · Score: 1
      C++ iostreams are built on top of C io functions, no?
      The C++98 spec doesn't specify mechanism, only policy. You can make a conformant C++ iostreams mechanism out of C tools, but why would you want to? You can do an awful lot better.
    19. Re:One example of why the tests are BS by mypalmike · · Score: 1

      And you are a coward. My point was cout is generally slower than C IO. So "puts", OK. Geesh!

      --
      There are 0x40000000 types of people: those who understand 32-bit IEEE 754 floating point, and those who don't.
    20. Re:One example of why the tests are BS by ChaosDiscord · · Score: 2, Insightful
      You would do it if you need a scrap object only sometimes (and didn't want to pay the overhead penalty of instantiating it every time the proc got called).

      If it's C++, you can scope the variable to the block you need it in. The object should not be instantiated until (and if) the block is entered. C++ scoping fills me with more happiness than is probably healthy. The idiom "/* Read the file */; { FileLockObject thelock(filename); ReadFile(filename); }" is just so wonderfully clean. No matter how you exit the block (return, continue, break, throw), the lock is released immediately.

      Of course, your point is still valid. In more complicated functions you might have an object that is optionally created and must visible throughout a larger block or function. In that case, yes, you'd do exactly what you suggest. I've certainly done it myself.

      BigObject * tmp = 0;
      if(RareCondition()) {

      tmp = new BigObject;
      }
    21. Re:One example of why the tests are BS by shakah · · Score: 1

      [...really poor example...]

      Why wouldn't you just do:
      void foo() {
      ...
      if ( SomeRareCondition() ) {
      AReallyNastyObject a ;
      ...
      }
      ...
      }
    22. Re:One example of why the tests are BS by Anonymous Coward · · Score: 0

      Wrong!

      if ( SomeRareCondition() ) {
      AReallyNastyObject temp; ...
      }

      This will work just fine and the object is only constructed if the scope is executed.

    23. Re:One example of why the tests are BS by andy55 · · Score: 1


      You didn't understand what he was saying.

      Ok, I hate to feed the trolls but fuck it... He posted:

      Why allocate and deallocate an object within the scope of a function? Well, in C++, there's no reason, so this is bad code.

      Now look at my post--I wasn't addressing the heap vs. stack issue directly--I was just answering his question. Indirectly I did address the stack issue because, pesumably, a big and nasty object with more than a couple k worth of instance data would never want to be put on the stack anyway! Stop acting like a lawyer, dude.

      Your code is making the same mistake because it should instead declare the object on the stack, like this:

      AReallyNastyObject temp;

      Look, no delete required, and it's faster, too.


      You have made clear you don't have a solid idea of what C++ code generation looks like.
      .

    24. Re:One example of why the tests are BS by boneshintai · · Score: 2, Insightful

      That's not useful.

      void foo() {
      ...
      if ( SomeRareCondition() ) {
      AReallyNastyObject temp;
      ...
      }
      ...
      }

      does essentially the same thing, but is less error-prone than an operator new/operator delete pair -- consider what happens if an exception occurs between your new and delete.

      There's basically no reason to allocate a single object using new and delete it within the same scope. Allocating arrays, or allocating an object for use in a different scope, are okay.

    25. Re:One example of why the tests are BS by mypalmike · · Score: 1

      And if the code were written with local objects, the code would have been:

      val = toggle.activate().value();

      And the g++ compiler would hopefully realize that it's a non-virtual function call and potentially inline it.

      Not that I was thinking about that originally... :)

      --
      There are 0x40000000 types of people: those who understand 32-bit IEEE 754 floating point, and those who don't.
    26. Re:One example of why the tests are BS by andy55 · · Score: 1

      There's basically no reason to allocate a single object using new and delete it within the same scope. Allocating arrays, or allocating an object for use in a different scope, are okay.

      Sigh. See my other post to the guy who jabbered this--you don't want to put certain objects on the stack.

    27. Re:One example of why the tests are BS by Bloater · · Score: 1

      Yes, I put that in my comment, but in this case it wouldn't be difficult for the compiler to spot that it can inline the method calls even though they are virtual.

      And since these classes are supposed to be used in some of the other benchmarks, it may be best to leave them virtual to fairly compare how a real program would be written.

    28. Re:One example of why the tests are BS by rjh · · Score: 2, Insightful
      My prior message might not have shown why it's not wise to build a C++ iostreams implementation on top of the conventional C facilities. So let's try something nice and simple.
      char *foo = "Hello, World!\n";
      printf("%s", foo);
      Straightforward, right? So here's the question: when does the program figure out how to display foo?

      The answer is--at runtime. Printf takes two arguments, has to evaluate them, has to parse the format string, has to figure out how to splice the data into the format string, etc., etc. (Note that printf doesn't even know what kind of data you're giving it; it literally has to interpret the parameter list at runtime. That's the major performance problem with vararg functions.) Compare this to
      std::string foo("Hello, World!");
      std::cout << foo << std::endl;
      ... where, thanks to C++'s much superior type system, the C++ compiler knows at compile-time that foo is a string, and that allows the C++ iostreams facility to generate much better code than the C-style "let's figure everything out at runtime" way.

      Short version: a decent implementation of C++ iostreams will wipe the floor with C-style I/O. If you're seeing performance penalties from C++ iostreams, the first thing you should do is make sure the problem isn't in your own code; the second thing you should do is make sure your iostreams library isn't built on C libraries that determine type information at runtime.
    29. Re:One example of why the tests are BS by BenjyD · · Score: 1

      Time with the original methcall.cpp=1.760s
      Time with objects on the stack=0.789s
      Time with objects on the heap but with non-virtual functions=0.799s

      Looks like you're right about the inlining. That's with 100000000 for an argument and on an A1800XP+.

    30. Re:One example of why the tests are BS by boots@work · · Score: 1

      Why would you not want objects on the stack? It's not like we're in kernel mode where there is only a small stack. In Linux userspace it is fine to put several k on the stack.

      Perhaps you're saying that a large object might have an expensive constructor? But that is equally much of a problem if it's constructed with new/delete. The solution is not to create/destroy it from inside the function. It doesn't matter whether it's on the heap or not.

    31. Re:One example of why the tests are BS by boots@work · · Score: 1

      You have made clear you don't have a solid idea of what C++ code generation looks like.

      I don't know about the original poster, but I think I have a moderately good idea. What is different in the code generation between creation of an object on the heap and on the stack? Inquiring minds yearn to know.

      Surely the same constructors gets called the same way? The only difference is whether the allocator gets called, or alternatively that the stack registers are frobbed.

    32. Re:One example of why the tests are BS by Anonymous Coward · · Score: 0
      In my experience, g++'s iostream library is dog slow. For a computer competition I was running last year, contestants could code in Pascal, C, or C++. Someone brought up a concern about being able to read a particularly large data set in time in all languages. C took 300msec, so I thought it would be no problem. Pascal beat C at 200msec, for the reason you give (no format to string). However, when I switched it to an ifstream, it took 3 seconds.

      I ended up altering the task to avoid this stupidity. When I related this story to coaches from a couple countries (after the competition), they conveyed similar experiences (most had told their team members to use C-style I/O to avoid it). An older g++ worked better, so it's not inherent to the language, but the implementation (much like my recent experience with grep 2.5 taking 100 seconds to grep a 5MB file for a simple string v. 0.3 seconds for grep 2.4).

      No languages offers sufficiently large advantages that a lazy-enough programmer cannot overcome them to produce bad code.

    33. Re:One example of why the tests are BS by Anonymous Coward · · Score: 0
      My prior message might not have shown why it's not wise to build a C++ iostreams implementation on top of the conventional C facilities. So let's try something nice and simple.

      char *foo = "Hello, World!\n";
      printf("%s", foo);

      Straightforward, right? So here's the question: when does the program figure out how to display foo?


      It figures it out at compile time.

      Why? Take a look at the following code, which is more efficient with the same effect:
      char *foo="Hello, World!\n";
      fputs(foo, stdout);
      fputs, as you know, prints a line of text to a specific stream. While it does need a destination stream in the parameter list, it does not need to spend resources at compile time to determine what is going to be printed.

      Your comparison between printf and cout is apples-and-oranges. They are two different things. Besides, with the printf series of functions, it is easier to perform control over formatting if you need to use a string in a different location in the program (e.g. sprintf.) There isn't any obvious equivalent for C++ - even if it does exist in the standard libraries, it is either obscure, or is not taught as well as it could be.
    34. Re:One example of why the tests are BS by halosfan · · Score: 1

      I didn't mean it was impossible to avoid runtime vtable lookup in Java, I said it was impossible to avoid virtual methods in Java. The difference is that while a JVM can optimize certain vtable lookups away, there is no way for the programmer to force this in a way portable across JVM implementations.

      --
      My only problem with Microsoft is the severity of bugs in their software.
    35. Re:One example of why the tests are BS by Alexis+de+Torquemada · · Score: 1
      Modern JVMs can actually inline many virtual method calls.

      And this is another reason why the test is unfair - he used the -O2 option to GCC, which does not enable function inlining. He should've used -O3.

      At first, I thought the test was rigged. But according to one variant of Occam's Razor, never attribute to malice what can be explained by plain stupidity. He's probably just an idiot.

    36. Re:One example of why the tests are BS by Alexis+de+Torquemada · · Score: 1
      Ok, I hate to feed the trolls but fuck it... He posted:

      You hate to feed yourself, troll?

      Now look at my post--I wasn't addressing the heap vs. stack issue directly--I was just answering his question. Indirectly I did address the stack issue because, pesumably, a big and nasty object with more than a couple k worth of instance data would never want to be put on the stack anyway! Stop acting like a lawyer, dude.

      His question - by the letter - was about allocation. But by the spirit it was about heap allocation. It's you who's either unable to comprehend, or acting like a lawyer. Btw, only idiots would create C++ structures/objects with several K in size (large allocations should use a pointer to the heap), and the structure in question certainly is much smaller.

      You have made clear you don't have a solid idea of what C++ code generation looks like. .

      You've made it very clear that you don't know the f*cking difference between heap and stack allocation in C++. Now go feed yourself, or don't.

    37. Re:One example of why the tests are BS by Alexis+de+Torquemada · · Score: 1
      Btw, only idiots would create C++ structures/objects with several K in size

      I take that back since these days stack size does not have relevant hard limits anymore. Structures containing bulk data may occasionally be useful if the size of the data is fixed.

    38. Re:One example of why the tests are BS by Alexis+de+Torquemada · · Score: 1
      The problem is that g++ probably does not optimise it all inline, whereas the particular java VM he has chosen to use probably does. Although defining the Toggle variables with auto storage class may give g++ the hint it needs to realise this.

      He passed -O2 to gcc, which does not enable any function inlining. GCC doesn't need any more hints here, it needs a single compiler option that the author is too ignorant/biased to figure out.

    39. Re:One example of why the tests are BS by Alexis+de+Torquemada · · Score: 1
      C++ iostreams are built on top of C io functions, no?

      But they shouldn't be built on top of printf, but rather primitives like read and write.

      The last time I benchmarked cout was a while back, so things might have changed, but they were ridiculously slow compared with straight C, at least in the libraries I was using.

      GCC's implementation, unfortunately, sucks a lot, performancewise.

    40. Re:One example of why the tests are BS by cimetmc · · Score: 1

      You should try with GCC 3.4. There has been some serious tuning of libstdc++ especially in the iostream and in the string areas and on some cases, GCC 3.4 may be quite a bit faster than GCC 3.0 through 3.3 when using the iostream library.

  58. Re:my arse by kaffiene · · Score: 5, Informative

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

  59. Next step by localman · · Score: 1

    Now if they can just make a decent cross-platform runtime. Or let me compile it into a binary so I don't have to depend on whatever they've got or send them the whole runtime myself.

    Or something like that. I really enjoyed my personal java project, but when I tried to do anything more advanced I just ran into such cross platform garbage that I couldn't see straight. I ended up using OpenGL instead.

    I still have some long term hope for Java, though.

    Cheers.

  60. Provide link please! by 3770 · · Score: 2, Insightful

    Please point me to a source which verifies your claim.

    --
    The Internet is full. Go Away!!!
    1. Re:Provide link please! by gamesmash · · Score: 1

      http://www.cs.cornell.edu/vogels/weblog/2002/11/24 .html

    2. Re:Provide link please! by gamesmash · · Score: 1

      Ok, I guess I should write more then.

      The link is cornell.edu

      The link points to a cornell cs researcher, he notes:

      "C# on the 1.1 .NET framework performs consistently better than Java on the best VM I know of (IBM 1.3). On the small memory models the C# version the composite result is about 20%-25% better than the Java one."

    3. Re:Provide link please! by 3770 · · Score: 1

      This is interesting. Thanks.

      I don't expect the Nobel prize for this but it seems as if you can prove that any language is the "fastest", you just have to skew the test to your advantage. This is probably not on purpose in many cases, it just reflects that the author is more familiar with one language.

      What is really needed is a community effort where proponents of each language really try to optimize their language of choice. Benchmark authors often ask for help optimizing his tests, but it rarely results in a new article.

      This mini-rant was not meant to discredit the information in the link. I found it helpful and interesting. I'm just a little frustrated that the results vary so widely between tests.

      --
      The Internet is full. Go Away!!!
  61. Re:c# is faster!!! by Anonymous Coward · · Score: 0

    Ok, I'll bite.

    C# cannot be faster than Java because it is an evil clone of Java. It will run at the same speed, or even slower.

    Thanks for playing fanboy!

  62. Re:This doesn't make any sense... by Anonymous Coward · · Score: 0

    Sigh... for the 100th time now:
    The JVM features a dynamic compiler; this profiles the application as it runs, then compiles the bytecode to highly optimized native code. It doesn't compile everything to native code when it is first used (as a JIT does), because then it couldn't spend a lot of time optimizing the code (which costs a lot of time).

    This means: after a while, you Java app runs as native code, optimized for your particular CPU (no i386 or other stuff; it uses SSE if possible, ...).

    murphee

  63. No News by Anonymous Coward · · Score: 0

    Kernighan/Pike revealed this years ago - the hopelessness of C++ that is.

  64. Some performance myths by vlad_petric · · Score: 5, Interesting
    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.

    --

    The Raven

  65. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

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

    They may not have respect for code, but at least they're making stuff. How's that new finance/office/anything real/custom software you're writing in asm coming along?

  66. C++ hash code is hobbled? by Sebastopol · · Score: 2


    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.

    --
    https://www.accountkiller.com/removal-requested
    1. Re:C++ hash code is hobbled? by Anonymous Coward · · Score: 0

      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!

      The hash_map doesn't copy the contents of the array, only the pointer. In the first loop, his code creates a copy manually because of this. In the second loop, he's just leaking memory. Even the memory allocated in the first loop leaks when the hash_map goes out of scope.

      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.


      I doubt that would matter much when it came to performance.

      Isn't it weird that the code sucks? You would think that someone who is willing to go through the effort of writing benchmark code would try to avoid doing stupid stuff. Take this excerpt from heapsort.java:

      double []ary = (double[])Array.newInstance(double.class, N+1);

      Any programmer with any amount of experience in C++ or Java would have written

      double[] ary = new double[N+1];

    2. Re:C++ hash code is hobbled? by Sebastopol · · Score: 1

      Ah. I see. I'm used to using strings or ints as keys in std::map functions. I don't normally use hash_map because it's not in the g++ 3.1 distro (my company mandates this version).

      Is there another source for free STL implementations out there besides the archaic SGI STL?

      not sure about ::hash_map, but the ::map lookup calls a function in this case. using k->second would dereference an ESI pointer to memory, which is faster than an inline call to a member function. not sure if hash_map does the same. yes?

      --
      https://www.accountkiller.com/removal-requested
    3. Re:C++ hash code is hobbled? by cheesybagel · · Score: 1

      Heh, now I found out someone had already noticed that about hash. You are not crazy, it is just that the person who wrote that code doesn't seem to know how to program in C++.

    4. Re:C++ hash code is hobbled? by roboteeruk · · Score: 1

      Other than stlport?

    5. Re:C++ hash code is hobbled? by Anonymous Coward · · Score: 1, Informative

      Ah. I see. I'm used to using strings or ints as keys in std::map functions.

      Most C++ programmers would do that. Then again, most C++ programmers would also bother to deallocate the arrays returned by strdup(), too, so I guess this guy isn't a C++ programmer.

      I don't normally use hash_map because it's not in the g++ 3.1 distro (my company mandates this version).

      IME, most people don't use hash_map, since it's not standard. My understanding is that it will be standard in the next revision of the C++ standard, so maybe it will gain more popularity then.

      Is there another source for free STL implementations out there besides the archaic SGI STL?

      Ever used STLPort? It's supposed to be pretty decent, considering that it's free.

      not sure about ::hash_map, but the ::map lookup calls a function in this case. using k->second would dereference an ESI pointer to memory, which is faster than an inline call to a member function. not sure if hash_map does the same. yes?

      You're right. It probably would improve performance to some measurable extent. The previous post stating otherwise is probably wrong.

  67. been there, done that by Anonymous Coward · · Score: 5, Informative

    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 is a critically-acclaimed fight simulator that was written almost entirely in Java.

    1. Re:been there, done that by Anonymous Coward · · Score: 0

      Where'd you hear that the game is a Java game? I'd be much more interested in the game if it were.

    2. Re:been there, done that by mrm677 · · Score: 1

      2) While it's not an id game, IL2 Sturmovik is a critically-acclaimed fight simulator that was written almost entirely in Java.

      Java may be used for some game logic, but the rendering engine is not Java.

    3. Re:been there, done that by Midnight+Thunder · · Score: 2, Interesting

      Although I could only find this in regards to Java in the game, you'd be surprised how fast graphics can be in Java if you use the right graphics library. One which I have looked at is OpenGL for Java. It is essentially a Java language wrapper around the native OpenGL libraries. Given that more and more of graphics processing is done by the video card, then the graphics part of Java in this instance, would be as fast as your graphics card.

      --
      Jumpstart the tartan drive.
  68. Bad Comparison by PalmKiller · · Score: 1

    The code in the c++ examples is really pretty much the slowest implementation that could have been written. I suspect he used the absolute best java code he could, but used generic c++ code.

  69. Re:That's what happens with the lowest common GUI by Anonymous Coward · · Score: 0

    Perl/Tk has to be able to work with X Windows, Apple and Microsoft. So it's stuck with the lowest common elements of all the operating systems it can run on.

    But wait - Perl/Tk apps suddenly don't look like something someone might pull out of overused public bathroom! They actually look pretty normal, fast and pretty.

  70. Re:Caught up with the speed, but still the ugliest by rms_nz · · Score: 1

    I'd say AWT was much more ugly - Swing in comparison looks pretty good

  71. Very true, if don't nkow what you are doing by Pac · · Score: 4, Informative

    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.

    1. Re:Very true, if don't nkow what you are doing by cheezit · · Score: 1

      "After a while the ugliness ceases to be a problem"...only cos you get used to it!

      --
      Premature optimization is the root of all evil
    2. Re:Very true, if don't nkow what you are doing by Midnight+Thunder · · Score: 1

      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?


      Maybe a case of spending too much time with CDE?

      --
      Jumpstart the tartan drive.
    3. Re:Very true, if don't nkow what you are doing by Anonymous Coward · · Score: 0

      Is there a "GodDamnItJustMakeTheFuckingWidgetsLookLikeAllTheO therWidgetsOnTheDamnHostMachine()" method?

  72. what the hell? by minamar · · Score: 1

    I don't hate java, but the results don't make sense. If the code is implemented in the same manner for processor bound tasks, there is no reason that java would out perform C++. Java isn't fully compiled (it runs on the JVM) and necessarily has extra overhead.

  73. Ridiculous by ddelrio · · Score: 1

    Either the G++ compiler is subpar, Sun just did some optimizations for people who don't know how to code, and/or Java's grabbing more resources and the G++ compiled programs are running at a lower priority.

    There is no way that a language that is running through simulated hardware is going to be faster than a program that is running on the hardware it was compiled for.

    1. Re:Ridiculous by Mithrandir · · Score: 1

      There is no way that a language that is running through simulated hardware is going to be faster than a program that is running on the hardware it was compiled for.

      Really? Perhaps you need to do some reading about HP's Dynamo project. It was even posted here as an article a year or two ago. A VM that makes native code faster than running the native code by itself. Dynamic runtime profiling and optimisation is always going to result in faster code than statically optimised.

      --
      Life is complete only for brief intervals in between toys or projects -- John Dalton
  74. Re:my arse by kaffiene · · Score: 1

    What? Because I gave Java another chance when it had matured and discovered that it's quite quiick these days?

    That makes me a language bigot?

    Rather than the typical /. post which is that Java is slow no matter what, or if it's not slow, then its ugly no matter what (ignoring the multiple GUI options like AWT / Swing / SWT or the skinnable options)?

    Excuse me if I'm not especially polite about it, but I'm sick of hearing this crap from /. I don't care if you want to stick to C/C++ - I use those languages still for somethings (small CLI programs are a good example) I don't care if people stick to what they know, but this endless uninformed bigotry that's displayed on /. is just pathetic.

  75. What about gcj? by joshv · · Score: 4, Interesting

    I'd be interested in comparing the speed of the native code generated by gjc to the that of JVM.

    -josh

    1. Re:What about gcj? by vlad_petric · · Score: 1

      GCJ is actually worse than standard (Sun/IBM) VMs. The reason - gcc optimization "stack" isn't doing that great for a language like java. It's actually not so good for C++ either, and that's why Intel C Compiler beats the crap out of g++ (20->30% perf. improvement is hardly uncommon).

      --

      The Raven

    2. Re:What about gcj? by joshv · · Score: 1

      er, that should read "native code generated by gcj"

    3. Re:What about gcj? by jefu · · Score: 1

      I was just looking at this with another program and gcj was substantially slower than native java. A big chunk of this was because the java compiler managed to inline a bunch of function calls, but even with that accounted for gcj was slower by 30 percent or a bit more.

    4. Re:What about gcj? by cbare · · Score: 1

      I used to think compiling java to native machine language would make it as fast as other compiled languages like C or C++. Not so.

      In Java you rely on automated garbage collection, which is basically a trade-off of speed for developer convenience. And all calls to (non-static?) methods are "virtual" -- in other words, they incure the penalty of dynamically determining the type of the object. Whenever you do an array access in Java, the index is checked against the bounds of the array, which must take a cycle or two. These are all part of the semantics of the language, and can't be "compiled away". (Optimized away at run time? Maybe somewhat. I dunno.)

      The philosophy of the language in general is to favor robustness, convenience, security, and Object Orientation over speed. This was a conscious decision.

      The results of this benchmarking are just as bogus as the one from TheServerSide a couple years ago claiming .net was faster than Java. Comparing languages like this is like saying hammer A is 20% faster than hammer B at house building. Other factors have much greater impact.

      In fact, it would be great if someone would now do a benchmark showing that C++ is faster than .net. That way we'd complete the loop and have: .net > java > C++ > .net

      That would be cool.

      --
      -cbare
    5. Re:What about gcj? by angel'o'sphere · · Score: 1


      'd be interested in comparing the speed of the native code generated by gjc to the that of JVM.


      The code generated by gjc is about 50% to 75% the performance of a JVM. (according to other posts on /. in different java related threads).

      angel'o'sphere

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  76. java *can* be fast... by alphafoo · · Score: 5, Interesting
    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]
    • hibernate
    • JAM on Maven [click]
    • eclipse
    1. Re:java *can* be fast... by Fnkmaster · · Score: 2, Informative
      Yes, EJBs are generally layers of needless cruft. There are lots of perfectly good situations that require distributed systems, and EJBs provide one of the worst models to solve truly partitionable problems and effectively distribute load, and if you just want reliability or failover capabilities, there are plenty of easier ways to get that than using EJBs.


      I agree with you - the only business apps I've seen that really NEEDED C++ were some very tight-loop mathematically intensive things where the 2x-4x performance difference imposed by lots of array bounds-checking became a limiter to performance optimization with the Java VM implementation - and that was easily solved by a small chunk of JNI code implementing the iteration over the arrays.

  77. Re:Caught up with the speed, but still the ugliest by I_Love_Pocky! · · Score: 4, Insightful

    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.

  78. Re:This doesn't make any sense... by Omnifarious · · Score: 1, Funny

    I actually find Java significantly more painful to develop in because it takes such a huge amount of time to start up the JVM that a debugging session is an exercise in fetching coffee. The class libraries are also poorly designed, and the language is excessively verbose.

  79. Re:This doesn't make any sense... by fozzmeister · · Score: 1

    Bloody Good Idea, Mod parent Up!

  80. Re:Caught up with the speed, but still the ugliest by Inf0phreak · · Score: 4, Informative
    Would you please turn off the moronic "smart quotes" feature in IE?
    Seeing things like this:
    I&#146;m
    is hurting my eyes.

    This page has more information about this horrible malfeature.

    --
    ________
    Entranced by anime since late summer 2001 and loving it ^_^
  81. Slow C++ compiler by siesta+at+uni · · Score: 4, Informative

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

    1. Re:Slow C++ compiler by foidulus · · Score: 1

      Off-topic, but it has to be said:
      You are right, GCC(while it's open source and great for most purposes) isn't a workhorse, and if Apple really wants to compete, they are going to have to stop using the GCC.(I know, IBM writes a compiler for their chips, but it doesn't really take advantage of the g5 platform in total) Apple has complete control over the platform, why haven't they written their own compiler for it yet? (Or at least made major contributions to gcc) Hopefully Steve will wow us at all the WWDC when he reveals a new compiler that is shipped free w/ Tiger...
      Now I'm off topic and a mac zealot, negative mods rain down on me!

    2. Re:Slow C++ compiler by Anonymous Coward · · Score: 0

      Maybe a better C++ compiler would change the results. But then again, there are many other Java virtual machines out there. IBM's, BEA's (JRockit) etc. etc. Some of those VM's might be faster than Sun's at certain benchmarks. For example, JRockit is claimed to excel at threading, IBM's at allocation.

      It's a moving target. The point is that for two very popular compilation platforms (Sun VM, g++). Java can be faster.

      The Intel compiler is often mentioned, but the reality is that the vast majority of Windows software is compiled with MSVC++ and the vast majority of Linux software is compiled with gcc or g++.

      The point to take away is that the typical knee-jerk 'Java is slow' slashdot opinion is getting less true everyday.

    3. Re:Slow C++ compiler by dsouth · · Score: 1

      One of the major problems is g++, not gcc. The KCC C++ compiler actually generated C code that was fed into the system's normal C compiler. When running on linux, this meant KCC was using gcc under the hood. Yet code compiled by KCC was often orders of magnitude faster than the same code compiled by g++. This was particularly true for STL heavy code.

      G++ does an admirable job of being faithful to the C++ standards, but in the performance arena it gets owned. Other compilers (IRIX C++, MS C++, and ICC) produce much faster code.

      As far as benchmarking goes, comparing g++ performance to anything is useless. Get a better compiler first, then benchmark.

      As far as MacOS goes -- hope that the IBM compilers eventually become the defaults, or that the g++ maintainers eventually admit that their optimization blows and then fix things. The former is probably more likely than the latter.

    4. Re:Slow C++ compiler by foidulus · · Score: 1

      As far as MacOS goes -- hope that the IBM compilers eventually become the defaults, or that the g++ maintainers eventually admit that their optimization blows and then fix things. The former is probably more likely than the latter.
      It is theoretically possible for Apple to contribute some more g5 optimazations to the g++ project(making it open source could only help them, as they really don't have any major pc competitors that run the same architecture) but it might just be easier/cheaper in the long run just to start from scratch.

    5. Re:Slow C++ compiler by dsouth · · Score: 1

      But the problem is not just lack of ISA optimization, it also has to do with front-end language optimization.

      As I mentioned in my post, KCC "compiles" C++ by converting it to C that gets fed into gcc, and yet produces executables that can have markedly better performance than g++. .All the G5 optimizations in the world are not going to fix g++'s problems -- your looking at the wrong end of the horse.

    6. Re:Slow C++ compiler by Anonymous Coward · · Score: 0
      Or at least made major contributions to gcc...
      Apple employs a number of people who work full time on gcc development.
    7. Re:Slow C++ compiler by Anonymous Coward · · Score: 0
      As far as MacOS goes -- hope that the IBM compilers eventually become the defaults, or that the g++ maintainers eventually admit that their optimization blows and then fix things. The former is probably more likely than the latter.
      The latter seems more likely(Note that IBM was a sponsor of the summit).
  82. Just-in-time compilation by Anonymous Coward · · Score: 1, Interesting

    The Just-In-Time Compiler in the JVM compiles the bytecode down to native code at runtime, so most of the time you're running what's effectively a native executable. Now, since the JITC runs at runtime, it can make optimizations based on the actual behavior of the program (as opposed to normal compilers, which don't have access to that information). That allows more aggressive optimization, effectively means you're running a native executable that's continually being optimized for your system. Pretty nifty.

    Now if only Swing wasn't so bloody inefficient....

  83. Re:Caught up with the speed, but still the ugliest by DeckerEgo · · Score: 2, Informative

    Also check out SkinLF from L2FProd - it's a library that makes it very easy to use GTK themes, KDE themes or even both together to make a very nice native-looking interface. I use it with ConsultComm and have had very nice results.

  84. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    If I was doing something low-level, I would use C or assembly. If I was developing a large (and perhaps distributed) application, I would use C++ or Java or C#. I would never use C or assembly in these roles so why would I care about comparing them with C++/Java/C#. Of course they're "faster". So what?

  85. Can I have an infinite budget to write the code? by IvyMike · · Score: 4, Interesting

    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.

  86. Now you're talking Profiling by GillBates0 · · Score: 4, Interesting
    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.

    --
    An Indian-American Hindu committed to non-violent thought/speech/action alarmed by the global explosion of radical Islam
    1. Re:Now you're talking Profiling by Anonymous Coward · · Score: 0

      Can gcc be provided with profiling information to make it do similar optimizations? (not being a smartass, I just don't know)

      I would say that the profiling that java does DOES give it an advantage, but why is it unfair? Couldn't someone reflexively argue that because java has to start up a jvm layer and C++ doesn't that C++ has an advantage? They're just differences in how each type of binary is run. Figuring out the net effect of the differences is the point.

    2. Re:Now you're talking Profiling by maraist · · Score: 1

      if the JIT/javac/JVM uses profiling information, gcc should too, for fair comparison.

      I disagree. What is being compared are stock products. It's like saying if this car has a turbo-charger, then it should only be compared to other cars that have a turbo-charger.

      This is more like comparing a toyota to a mustang. The mustang can accelerate faster, but the speed-limits of highways prohibit it from traveling faster than the toyota could travel.. The fact that the honda gets better gas mileage and thus requires fewer pit-stops gives the toyota an ironic "average speed advantage" over the mustang in a cross-country race.

      What is being shown here are two stock environments, "gcc" and sun's JRE. There are external profilers for BOTH gcc and java. What's more you can compile java down to assembly. But we are not testing a profiler or a cross-language compiler, we're testing the stock compilers.

      The author did say he might try Intel's compiler next. Likewise, perfectly valid tests would be a 3'rd party profiler as applied to gcc or Intel.

      My point is that the alleged java run-time profiling is merely an attribute of one product over another. If you required running a profiler on the gcc and not an external one on Java, then I would argue that Java is at a disadvantage, because java can't shut off it's internal profiler. ("-client" shuts off more than the profiler, it shuts off most of the useful jit as is thus a pseudo byte-code interpreter).

      --
      -Michael
    3. Re:Now you're talking Profiling by Timothy+Brownawell · · Score: 0, Redundant
      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.
      Why? In neither case did the programmer do extra work to provide profile data. If one tool can figure that out for itself somehow, that's a valid advantage. Which tool works better with a given amount of programmer time?

      Tim

    4. Re:Now you're talking Profiling by Anonymous Coward · · Score: 0

      So users should be charged less for java apps as their computer has to work harder (doing these magic run-time profiling optimisations), since normal commercial C++ programmers profile themselves?

    5. Re:Now you're talking Profiling by foidulus · · Score: 1

      The mustang can accelerate faster, but the speed-limits of highways prohibit it from traveling faster than the toyota could travel.. The fact that the honda gets better gas mileage and thus requires fewer pit-stops gives the toyota an ironic "average speed advantage" over the mustang in a cross-country race.
      I think the highliting speaks for itself :P Most people don't change cars in the middle of a comparison either :P

    6. Re:Now you're talking Profiling by Anonymous Coward · · Score: 0
      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.

      No, that would not be fair either. Thing is, with C++ that would mean pre-profiling, with known input sets. In Java, you don't need that -- it's done dynamically in runtime, on whatever input you throw it, as courtesy of JVM. Whether this is fair or not depends on many factorys; one of which is whether you even know a priori input data set and usage patterns or not. If you don't you can't even profile it for C++, in which case comparison is perfectly valid. Further, allowing C++ profiling based performance tuning adds more work to C++ side -- should Java implementation be allowed to be hand-tuned similarly?

      Personally I just think that Java JIT/HotSpot feature is a neat feature of Java platform -- just like C++ has its strength (say, faster startup since all optimizations are done in compilation phase, with no need for VM), and trying to eliminate such competitive bonus would be unfair, and useless exercices in orangefying an apple. It's a feature that derives from language design itself; inherent feature of advanced implementation of language's runtime environment.

    7. Re:Now you're talking Profiling by Dun+Malg · · Score: 1
      It's like saying if this car has a turbo-charger, then it should only be compared to other cars that have a turbo-charger.

      I think it's more akin to comparing a car that always comes turbocharged (java) to one that has the turbocharger as an option you have to specify before ordering (C++). Is it not more fair to compare the "always turbo" Java with run-time profiling with compile-time profiled C++?

      --
      If a job's not worth doing, it's not worth doing right.
    8. Re:Now you're talking Profiling by Nahor · · Score: 1

      What about the unfair advantage that C++ is natively compiled for a specific processor (and thus optimized for it) while Java is compiled for a virtual machine?
      What about the unfair advantage that C++ programmers can do tricks with pointers to make their application run faster while Java programmers can't?

      The two languages, while similar, are not identical. So you can always find the benchmark biased if you want to. It all depend on the "rules" you give yourself.
      If the benchmark is about coding an application that does something specific, it doesn't matter how the thing is done. If the program use a time machine to give the answer faster, that fine with me even if the real processing times is 100x slower than when using another language/environment.

    9. Re:Now you're talking Profiling by Anonymous Coward · · Score: 0

      He's comparing end-products. One big difference between Java and C is that Java DOES have runtime optimization, while C does not (by Java and C I mean everything from source code to, and including, execution). Are you saying that the tests are unfair because there are differences between C and Java?

      Consider the following hypothetical and oversimplified scenario: cpu X version A has an on-chip cache, while cpu X version B has no cache. A will generally perform better than B. Is that called an unfair advantage, or is it that A does the job better because of the cache?

    10. Re:Now you're talking Profiling by KnacTheMife · · Score: 0

      the prcedure of the study may have compared two stock products but the study is presented as comparing the languages and not the compilers, therefore I disagree with your post and find your analogy insufficient

      --
      -- "Someone's gotta go back for a shit-load of dimes."
    11. Re:Now you're talking Profiling by Trinition · · Score: 1

      If you'rebenchmarking "Java" against "C++", you need to define what each of those are. YOu say HotSpot profiling is unfair unless the C++ compiler cna also be allowed to use profiling data. But if "Java" means "A Java program running on Sun's HotSpot VM" (after all, a Java program is useless without a VM so it is reasonable to assume "Java" includes a VM), then that is part of "Java". Is it part of "C++"? It's not Java's fault that "C++" doesn't include runtime profiling.

  87. Java maturity vs. .NET by Tomster · · Score: 1

    Java has had a lot of effort put into it over the past four years. It's now a mature platform, with everything that label implies. I'm looking forward to the 1.5 release, and it seems the Java community is more excited by this release than anything since 1.2. .NET, on the other hand, still feels very much like a work-in-progress below the flashy GUI stuff that Microsoft is so good at (and which is perhaps the remaining major weakness in Java[1]). There are some things it gets "right" that Java doesn't, but it's clear that it's a 1.x release. Of course, Microsoft isn't standing still either. The resulting competition is good for both developers and end-users.

    [1] The problem is largely due to widespread ignorance concerning best practices for creating a user interface in Swing. In addition, GUI design tools are notoriously poor at generating good-quality code that does use good practices (though this is improving); and books provide simple, small examples suitable only for the toy applications they showcase. Most Swing developers learn the tricks of the trade through experience and code borrowing.

    -Thomas

    1. Re:Java maturity vs. .NET by kaffiene · · Score: 1

      Yeah, .NET is buggy as all hell and the tools have a real "beta" feel to them. I keep on getting prevented from doing perfectly legal things in the language (inheirance of panels or abstract classes) by the IDE because the %$#*$*!! GUI builder gets confused by them.

      Not to mention the fact that the language is poorly designed. It has keywords like out and ref which do almost exactly the same thing. C# was designed by one of the guys behind Delphi AND IT SHOWS. The C# RAD environment is a PITA for people who want to concentrate on code, not pretty boxes.

    2. Re:Java maturity vs. .NET by smileaf · · Score: 1

      only experience with .NET was with ASP. and I HATED it.

      the redundent properties (Asp:repeater's header and footer anyone?)

      the bad C# intergration problems made going to work a nightmare.
      C# in itself is a nightmare to look at compaired to C/C++ or even java.

      Finally the IDE's autoformatting pissed me off so much I thought about doing it in notepad. .NET may be improving but Java is Far better IMHO.

  88. c# is FASTER than JAVA by gamesmash · · Score: 2, Informative

    Because c# is faster than Java, and Java is faster than c++, then by transitivity, C# is faster than c++. To back up my claim that c# is indeed faster, I cite as my source a researcher at cornell: http://www.cs.cornell.edu/vogels/weblog/2002/11/24 .html

  89. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 1, Interesting

    A few months ago, I ran some Java code and comapred it to C (not C++, C is way faster) and the result, to my surprise, Java was faster. The functions in both sides were identical, but Java executed faster. I ran this with gcc Sun JVM 1.4 on Java Desktop System 1.0 and RH 9.0. If you don't beleive me, try it out.

  90. Meaningless, but... by groomed · · Score: 1

    Research like this is useful for the propagandist/advocate.

    Even though it completely fails to address issues such as startup time, runtime linking cost, and such minor nits as gc and compilation delays, as well as the way all these things interact as applications grow, not to mention as memory use, it does show that Java can do a mean synthetic benchmark -- and lacking pretty much everything else, that's all the propagandists really have.

    Most people will (or should) recognize however, that this is a lot like saying, "hash tables are faster than arrays!", without specifying the operation, the hash function, or the data set.

  91. Now with by Inf0phreak · · Score: 1
    --
    ________
    Entranced by anime since late summer 2001 and loving it ^_^
  92. Re:Caught up with the speed, but still the ugliest by ci4 · · Score: 1

    Since when is 33 less than 25?

  93. The language does matter by 3770 · · Score: 4, Insightful

    A few examples

    1) Java has bounds checking for arrays, C++ doesn't. This is specified in the language. This affects performance.
    2) Java has garbage collection, C++ doesn't. This is specified in the language. This affects performance.

    Also, the specification of Java says that it should be compiled to byte code and executed in a JVM.

    So the "language" certainly affects performance.

    --
    The Internet is full. Go Away!!!
    1. Re:The language does matter by bpellin · · Score: 2, Insightful
      Certainly the language affects implementation. However, the only relevant speed comparisons are between implementations of a language. Saying that language requirements/features will have an effect on performance is misleading.

      For example, good JIT compilers for Java are able to eliminate many bounds checks for arrays. Consider something like:
      for (int i = 0; i < 10; i++) {
      A[i] = ...
      }
      If the array A is of size >= 10, the compiler can easily prove the checks unnecessary, and the generated code will not contain bounds checks.
    2. Re:The language does matter by TRACK-YOUR-POSITION · · Score: 2, Insightful
      A third one I think is really important

      3) All Java classes are the equivalent of C++ virtual classes. There's a whole lot of dynamic type-checking, virtual function table lookups, and so forth when dealing with any Java objects, right?

      Which is what is striking to me about these benchmarks--there's all kinds of sorts and matrices and pure number crunching stuff, but I didn't see anything in which garbage collection or object management delays would start to become apparent. If what the other poster says about avoiding bounds checking is correct, that means that these benchmarks managed to avoid the major potential liabilities of Java performance.

      That's not to undermine the significance of these benchmarks--it's still very interesting that Java can approach and perhaps surpass C++ performance in any case with JIT.

    3. Re:The language does matter by gregor_b_dramkin · · Score: 2, Informative

      I believe you can declare a java method or class as "final". This optional behaviour is like C++'s default behaviour.

      BTW. I looked at the "shootout" article when it first reared its ugly head. I recall the Python code looking like it had been written by someone who had read 3 chapters of "Teach Yourself * in 21 Days". Utter crap.

      --
      You can never equivocate too much.
    4. Re:The language does matter by X · · Score: 1

      Yeah, the code is also structured to take advantage of a JVM optimization that doesn't exist in g++ (but does exist in icc). All the objects are allocated on the heap, so method invocations have an extra jump in them with g++. Smart C++ compilers and JIT's on the other hand tend to be smart and avoid the extra jump. If you look at the test where g++ performs most horribly (namely the "Method call" test), and compile it with icc, you'll find icc actually is slightly faster than even the server VM.

      --
      sigs are a waste of space
    5. Re:The language does matter by TRACK-YOUR-POSITION · · Score: 1

      You can? That's cool. If that's true, here's hoping that someone comes along to mod down my disinformation and mod you up.

    6. Re:The language does matter by Avumede · · Score: 1

      Yes, garbage collection could impact performance, but it might be beneficial. A good garbage collector is like a good run-time optimizing compiler - it can improve performance by making choices about garbage collection based on the system state, including history. The end result may be better than you can get by hand-coding.

      Not that Java's garbage collector is quite there yet in practice. It's best garbage collection routines (not enabled by default) are a bit buggy still.

    7. Re:The language does matter by ddt · · Score: 1

      1) Java has bounds checking for arrays, C++ doesn't. This is specified in the language. This affects performance.

      2) Java has garbage collection, C++ doesn't. This is specified in the language. This affects performance.
      Also, the specification of Java says that it should be compiled to byte code and executed in a JVM.
      So the "language" certainly affects performance.

      I believe I disagree with all of these.

      When Transmeta's Crusoe launched, it was not widely known that they had the fastest native picojava processor on the planet.

      To prove it, they compiled most of Doom down to x86 machine language, and then they compiled the exceedingly hot spots (rasterization) down to x86 for one executable and down to picojava for the other executable.

      They both ran at the same speed.

      You might say this is because Transmeta processors don't really run x86, but instead translate it to another format. That is correct. So does a JVM. So do Intel and AMD chips. Pentium processors haven't been native x86 processors since the original Pentium.

      The trick to most on-the-fly x86 optimizations is figuring out when the strict x86 behavior is necessary, and when you can bend the rules. If you're in the middle of bending the rules, and the processor receives an IRQ or generates an exception, you need to dump everything on the floor and back up to the last time you had a valid x86 state, otherwise, as long as the x86 state is the way it's supposed to be at the end of the block or trace or however much you can get away with, it's all good.

      This is true of Java bytecode as well. If you can simply trap out-of-bounds memory instead of doing an explicit bounds check on each access, your code will run very fast. If you get an exception, then it's back to the JVM. If you get lots of execptions, you can retranslate that particular block to do explicit bounds-checking and again manage to avoid calling the JVM.

      If your garbage collector learns individual app behavior and tailors its behavior to a particular application runtime memory allocation track record, you can get superior performance to C++ new()/delete()'s compiled to x86, depending on how much time the app developer got to profile his memory management system, a task all too often overlooked in today's memory-is-cheap-get-it-to-market rush.

      HP's Dynamo runtime actually proved that you can get better native machine language performance by running the native machine language in a runtime.

      Modern JVM's aren't executing bytecode. They're making fully native x86 translations, and the x86 translations jump to each other. In fact, you're not really spending much time running the JVM at all. Your program is getting compiled, linked, and is running native. It's only going to the JVM when it has to.

      The bottom line is that your Java perf is going to be wildly variable, depending on the quality of your JVM, and your x86 performance is going to be much less wildly variable, because x86 processors really became C++ bytecode processors several years ago. They're very carefully tuned to destroy benchmarks, particularly Winstone, which is a spectrum of bloated C++ Windows apps, a depressingly representative benchmark of what most of us run.

      However, Intel and AMD processors can't see or remember beyond a tight window of x86 instructions. They will make the same optimization mistakes over and over again, no matter how many times you run the application. If your hot spots are longer than the size of that window, you lose. JVM's don't have this restriction. They see and can remember the entire application.

      Nothing about x86 or C++ prohibits C++/x86 runtimes. This is precisely what Transmeta and VMWare are doing. They are both little companies and do not have the incredible muscle and financing of AMD and Intel, n

    8. Re:The language does matter by tunah · · Score: 1
      1) Java has bounds checking for arrays, C++ doesn't. This is specified in the language. This affects performance.

      Definitely.

      2) Java has garbage collection, C++ doesn't. This is specified in the language. This affects performance.

      Hmm... this is probably true in a lot of cases, but read this. (The guy's written a C++ compiler, and the D compiler - D is garbage-collected).

      Also, the specification of Java says that it should be compiled to byte code and executed in a JVM.

      Really? IIRC, the language spec only defines the semantics of the language, and the VM spec talks about the format of programs, so GCJ could in theory be compliant with the language spec, but the VM spec would be irrelevant. Of course the language was designed to be interpreted, so there are probably performance penalties in both JITed and precompiled code there...

      --
      Free Java games for your phone: Tontie, Sokoban
    9. Re:The language does matter by 3770 · · Score: 1

      Regarding item 2, I had a colleague at a University I worked at, which had a "proof" (I didn't look into it and it wasn't published but rather a good discussion and it was a bright guy) that a garbage collector was faster, in theory, in certain situations.

      I was actually intentionally vague in my statement. I only say that it affects performance, but I didn't say that it made Java slower.

      Because I actually don't know how it will end up.

      --
      The Internet is full. Go Away!!!
    10. Re:The language does matter by Pr0xY · · Score: 1

      pedantic note: VMWare does zero interpretation, it is nothing like a JVM, not even a JIT compiling JVM. VMWare and similar applications run in VM86 Monitor which is effectivly a "real mode" task in a protected mode operating system. All code runs nativley on the CPU except for instructions which are priviledged (ring 0) in which they get trapped by an exception handler (the vmmon kernel module) and are simulated, but these are a select few instruction for interacting with processes and hardware. This is nothing even close to a JVM style C++ runtime, this is whole machine virtualization, which is not the same as languages virtual machine at all.

      proxy

    11. Re:The language does matter by evenflow · · Score: 1

      Regarding item 2, I had a colleague at a University I worked at, which had a "proof" (I didn't look into it and it wasn't published but rather a good discussion and it was a bright guy) that a garbage collector was faster, in theory, in certain situations.

      In a copying garbage collector, the work required is proportional to the live memory. With manual memory management, the work is proportional to the amount of garbage. So given enough memory, garbage collection will always be faster, "even if the cost of freeing a cell is only a single machine instruction" (Appel). Garbage Collection Can Be Faster Than Stack Allocation by said Appel is a good start if you want to know more.

      The key phrase here is "given enough memory". And in my experience, I've never succeeded in giving real Java programs enough memory :->.

    12. Re:The language does matter by kmonsen · · Score: 1
      I do not think that is the same, if you write a class or method final the compiler will complain if you try to subclass or override the method. In c++ the method can be there, it just isn't checked for during runtime.

      If you say a method is private in Java, it will use invokespecial instead of invokevirtual. This is much faster and will not have the lookup penalties.

    13. Re:The language does matter by Q+Who · · Score: 1

      1) Java has bounds checking for arrays, C++ doesn't. This is specified in the language. This affects performance.

      No, it is not specified in the C++ language.

      CC -DEBUG:subscript_check=ON, that's MIPSPro CC.

      2) Java has garbage collection, C++ doesn't. This is specified in the language. This affects performance.

      C++ can have garbage collection plugged in.

      I don't think you really understand what C++ is and is not.

    14. Re:The language does matter by Anonymous Coward · · Score: 0

      > 1) Java has bounds checking for arrays, C++ doesn't.

      It's very easy to do a bounds-checking array class in C++ if you need it..

      > 2) Java has garbage collection, C++ doesn't.

      Garbage collection is a set of techniques and various approaches. Your solution highly depends on your needs. It took me a couple of days to implement a reference-counting base class in C++, I use it for those objects which really need that. Never had any problems with this simple GC.

      > Also, the specification of Java says that it should be compiled to byte code and executed in a JVM. So the "language" certainly affects performance.

      C++ spec doesn't say it's programs shound not run under some "C++ VM". It just never happened (maybe I'm wrong, but at least not in mainstream?).

    15. Re:The language does matter by Decaff · · Score: 1

      2) Java has garbage collection, C++ doesn't. This is specified in the language. This affects performance.

      In practice, C++ does have garbage collection of a kind. On a modern operating system, when you malloc() you arent getting 'real memory'; its all virtualized. That memory is managed and swapped. In effect, the operating system is 'garbage collecting' your memory to optimize access.

    16. Re:The language does matter by Anonymous Coward · · Score: 0

      This is near-complete nonsense.

    17. Re:The language does matter by 3770 · · Score: 1

      What part of what I said in my previous post is it that causes you to say that I don't understand C++?

      For something to be C++, it has to be in the standard, or at least be a defacto standard.

      It isn't enough that one particular compiler supports putting bounds checking in place.

      You need, for example, a standardized way to handle when an out of bound request has been made and that isn't in the standard as far as I know.

      Similarly, just because you can plug in garbage collection into one particular C++ program through a library or into the compiler doesn't mean that it is C++.

      --
      The Internet is full. Go Away!!!
    18. Re:The language does matter by Decaff · · Score: 1

      This is near-complete nonsense.

      So, you think that when you malloc() and get a pointer, that pointer is to a real physical memory address? Well, if you are programming an 8086 or writing hardware drivers, yes, but otherwise, no. Your program is running in a virtualized address space, which the kernel maps to physical pages.

    19. Re:The language does matter by jeremyp · · Score: 1

      This is not garbage collecting. Garbage collecting is automatically freeing memory when it is no longer in use. The virtual memory system has no way of telling when a process has finished with its memory until the process exits.

      When you malloc some memory and then use it, the OS has to allocate some physical RAM. If you then don't use it for a bit, the OS can say "OK he's not using this memory any more, I'll get rid of it" but it can't throw the memory away so it saves it in the swap space. If you use enough virtual memory, eventually both the physical RAM and swap space wil become full. At that point your server keels over in a heap (no pun intended).

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    20. Re:The language does matter by Anonymous Coward · · Score: 0

      This is why I said 'garbage collection of a kind'. The point I was trying to make is that any application running under a modern OS is subject to a lot of background memory management.

      The aspect of this memory management that seems rather like garbage collection is the handling of fragmentation. Even without memory leaks, a program that performs many malloc()s and free()s will fragment the process memory. This requires either sophisticated memory management to make non-contiguous areas appear as one, or alternatively some work to coalesce areas.

      There is a lot that goes on behind the scenes!

    21. Re:The language does matter by fatphil · · Score: 1

      It would always require one bounds check, as how else would it know that array A is of size >= 10.

      FP.

      --
      Also FatPhil on SoylentNews, id 863
    22. Re:The language does matter by fatphil · · Score: 1

      There's a difference between
      - C++ doesn't have bounds checking, that's in the standard
      and
      - C++ doesn't have bounds checking in the standard.

      You meant the latter, you wrote the former.

      FP.

      --
      Also FatPhil on SoylentNews, id 863
  94. more Java perf. tips at javaperformancetuning.com by Kunta+Kinte · · Score: 1
    You can always get many Java Performance Tips at http://www.javaperformancetuning.com/.

    Great website for any Java programmer. Has helped me quite a bit.

    --
    Based on upvotes, Ageism is the only "-ism" Slashdotters care about and think isn't SJW
  95. one out of two..... by MarkEst1973 · · Score: 1

    one out of two ain't bad....

  96. C++ streams can be CPU-limited -- SLOW!!! by Anonymous Coward · · Score: 0
    As for "several orders of magnitude," I call bullshit.

    You know not of what you speak. Try using C++ streams vs. write() on a fast disk - something like a SAN.

    See the write()'s move data a 200+ megabytes/sec. See the C++ streams struggle to break 2 megabytes/sec.

    1. Re:C++ streams can be CPU-limited -- SLOW!!! by pclminion · · Score: 1
      But you missed my point, which is that comparing write() to C++ ostreams is not a fair comparison, because write() goes directly to the OS, whereas the ostream has buffering logic. Moreover, the efficiency of the stream depends highly on the implementation, which has no theoretical limit on badness.

      If I gave you a hacked up version of the C library that purposefully wasted time whenever you called a library function, would you then tell me that C is naturally a slow language? Of course not.

    2. Re:C++ streams can be CPU-limited -- SLOW!!! by Anonymous Coward · · Score: 0
      But you missed my point, which is that comparing write() to C++ ostreams is not a fair comparison, because write() goes directly to the OS, whereas the ostream has buffering logic. Moreover, the efficiency of the stream depends highly on the implementation, which has no theoretical limit on badness.

      Why isn't it a fair comparison? C++ streams are nothing more than wrappers around the basic IO kernel traps - i.e., they're fluff. And they're slow fluff, like most of C++.

      C++ seems designed for use on commodity-type desktops where there are CPU cycles to burn and a good amount of RAM.

      Oh, and the performance of everything on this planet "depends highly on the implementation".

    3. Re:C++ streams can be CPU-limited -- SLOW!!! by Anonymous Coward · · Score: 0

      Back up your claims with some real numbers or shut the fuck up.

  97. Re:Can I have an infinite budget to write the code by Sebastopol · · Score: 1, Interesting

    "The C++ version would have taken longer to write and debug."

    Right on.

    Unix GUIs are far easier to implement with Java than with C++. Athena/Xlib are a huge fargin' hassle and no-one ever gets the widgets right. Motif is too expensive to license.

    In my two decades of experience, even multi-million dollar engineering apps still don't understand the concept of WINDOW RESIZING!!!

    I wish all Unix GUIs were done in Java.

    --
    https://www.accountkiller.com/removal-requested
  98. Re:Caught up with the speed, but still the ugliest by FedeTXF · · Score: 3, Insightful

    I can say after using SWT in the Pocket PC platform that it sucks. The widgets are primitive, lack any real model implementation, they brake compatibility between minor versions, the most advanced things are done in the Eclipse UI packages not in the widget toolkit and the code you end up writting is ugly.

    Elaboration:
    No model: with swt you get the widget as a UI object with a field of type Object that you may or may not use as a reference to the object dislpayed. You ahve to write the code that updates th view when the underlying object changes and hende there is not real MVC pattern there. You can do it yourself. Imagine the huge pile of repeated effort in many projects around the world.

    Primitive widgets: the table widget is just a string grid. No masked text input, and it goes on and on.

    Ugly code: they use public fields for setting state to widgets not constructors or factory methods or even setters. They have integer constants for decribing widgets and you have to use those and see them. Creating a label requires using new Label(SWT.LABEL) and creating a horizontal Line is new Label(SWT.LABEL | SWT.HORIZONTAL). So much for hiding complexity.
    There are 4 type of layout managers, the initialization is verbose and in fact only 1 are relevant, GridLayout, the other 3 are special cases of the former.

    The more advanced widgets are not in SWT, only in the Eclipse centered custom libraried. The SWT mantainers say those classes are for use in the eclipse UI and they don't mean thme to be general purpose, use thej if they fit, but don't ask for improvements.

    The only way SWT is justified is when you have very low resources (a pocket pc) or need to compile with gjc. Otherwise, Swing is way better even when it is far from pefect.

  99. Re:Caught up with the speed, but still the ugliest by Tobias+Luetke · · Score: 1, Interesting

    You can skin it as long as you like it will still not be native and not look native.

    You will not be able to get windows cleartype or X11 anti aliasing font smoothing in a swing app.

    Sun needs to embrace SWT or make something better ( thats not hard ) but whatever they declare for standard has to honor the platforms native appearance, there is no other way.

    P.S: yes i have seen beautiful swing apps, yet they look out of place.

  100. In Hardware? by gerf · · Score: 1

    Hear me out. At my school, there's a project in collaboration with the US Dept of Defense to make a hardware compiler for Java. This is because the government likes using Java for its ability to run on so many platforms, but they also want it to be faster if it's running some critical system in aircraft.

    Though a hardware implementation would be cool, i doubt it'd make a large impact in the civilian sector, due to cost.

    1. Re:In Hardware? by aka-ed · · Score: 1
      Perhaps me stupid.

      Once the DoD and your school do all the heavy lifting and perfect the hardware implementation, what would be the terrible cost to the civilian sector (assuming you could incite sufficient demand for economies of scale)?

      --
      I survived the Dick Cheney Presidency 7 to 9 AM 7-21-07
    2. Re:In Hardware? by gerf · · Score: 1

      Creating another chip ads just a bit more cost to a computer. And where would you put that chip? on the mobo? as another ad-on card? I have no idea how large it'd be (probably not very), but it'd still be another thing to add. Think of it along the same lines as DVD-rom decoding cards that were more in use with older computers: faster, but not needed.

    3. Re:In Hardware? by dasmegabyte · · Score: 1

      I'd put it in a brand new case and install the JDS on it.

      --
      Hey freaks: now you're ju
  101. O3? Equivalent programs? by morcheeba · · Score: 4, Insightful

    Why did he use only -O2?

    -O3 adds function inlining and register renaming.

    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 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. Re:O3? Equivalent programs? by Anonymous Coward · · Score: 0

      Why did he use only -O2?

      Because using -O3 would have made C++ look better, and he was trying to make it look bad.

      The many examples of poor programming in the C++ versions of the benchmarks can perhaps be chalked up to incompetence rather than malice, but you can never be sure.

      These results are worse than useless. Badly executed and perhaps even dishonest benchmarks just poison the environment for the next competent and honest attempt at a comparison.

  102. Troll by stratjakt · · Score: 5, Insightful
    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.
    --
    I don't need no instructions to know how to rock!!!!
    1. Re:Troll by wmshub · · Score: 1

      > This test proves that Sun's optimized Java compiler and VM are faster on Red Hat than gcc.

      It also proves something even more interesting: It proves that the speed difference of C++ vs. Java is smaller than the speed difference of a good vs. a not-no-good compiler.

      So, in other words, if you choose to use C++ over Java for the speed difference, then use any old C++ compiler you have handy, you're not making very smart decisions. They days when you could just assume that Java would be half the speed (or worse!) compared to any old C++ compiler are over.

    2. Re:Troll by Ninja+Programmer · · Score: 2, Informative

      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 is a slight misrepresentation. gcc actually does quite respectably on x86 platforms -- its easily as good as MSVC++, and its clear that the gcc people have put a lot of work into this compiler. Of course, the Intel C++ compiler is truly awesome and leaves pretty much every other x86 compiler in the dust, but this is really a case of Intel just putting a truly amazing effort into their compiler rather than anyone else comming up short.

      The real issue with these tests is that pretty much none of them have real computational inner loops. They all measure unlikely program overhead that could easily be removed with any reasonable rerendering of the code.

    3. Re:Troll by KZigurs · · Score: 2, Insightful
      " 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)."

      As far as I understand ONLY field where Java can be used succesfully now IS THE server side. And believe me - there is way more ordinary programmers that happily crunch their daily duties creating xml/xsl/html/xhtml/whatever spitting JSP's or servlets than hardcore C++ GUI developers.

      Of course this will probably change once Java will get something decent for graphics, maybe even Qt in native Java... Existing graphical layers are simply sickening to work with.

      But for everything else - there is a nice, decently fast (and believe me - you DO NOT need those 16xCPU power5 grids or that 8.244012% difference in execution speed - when developing you always should be looking for simplest/easiest and most practical solution. At least in the main cases. It MAY be different if you are one of CuBase developers.).

    4. Re:Troll by mattgreen · · Score: 1

      And michael passes it on as if it were news! The circle is complete!!!

    5. Re:Troll by Tim+C · · Score: 1

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

      There's no such thing as "server-side Java", other than to distinguish between what I do (writing code that runs on a web server) from what some other people might do (eg creating apps like JBuilder, or applets, etc). The -server switch just tells the JVM to behave in a way that's more appropriate for a long-lived application - take a performance hit on startup, use more memory, change the behaviour of the garbage collector, etc, so as to improve performance in the long run. If your code is only going to run for a few minutes, then it's probably not worth it. If it's going to be hanging around for a while, then it most certianly is.

      That doesn't mean that it can only be used on a server, though - for example, I use JBuilder at work, which is regularly running for weeks on end. That's a good example of a client app that would definitely benefit from running under a JVM with the -server switch (which reminds me, I really ought to see if it does...)

  103. Magicosm by wurp · · Score: 2, Informative
    Magicosm is a 3D real time persistent online world. It's not released yet, but we have about a dozen beta testers. If we were funded, we would be way done by now; working on things only in your spare time is a bitch ;-)

    We use Xith3D (primary written by our main client developer), a Java3D workalike. Xith3D was spun off in response to Sun's news that Java3D would no longer be supported. Sun's decision may have been reversed; I'm not entirely sure.

    Anyway, we have slick looking 3D that performs just fine; comparably to other engines. It's on top of an API (Xith3D/Java3D) that sits on top of opengl.

    There have been several good 3D java games displayed at the GDCs, stuff from FullSail and GetAmped.

    By the way, the project is currently going through a lull as I work on another side project (an online yard sale) and the primary client developer has had to leave the team to spend more time with his family. Send us a note at jobs@magicosm.net if you want to help out as a developer, 3D artist, system administrator, or (especially) investor!

    1. Re:Magicosm by Mithrandir · · Score: 1

      Adding to that (Sun has said they're going to release the J3D source, but no word on the license yet).

      The Java+OpenGL apps are very impressive. As an additional view, we have our our Java/OpenGL scene graph called Aviatrix3D which is aimes that the sci-viz end of the scale. Already, without serious optimisations, we're running twice the frame rates of Java3D. As a better benchmark, when it's under the base of a VRML/X3D browser, we're getting a least twice (typically 3 to 4 times) the frame rate, if not more than any other VRML or X3D browser written in C or C++ (eg Cortona, Blaxxun, Flux, etc). It's all about how you code, not what you're coding in.

      --
      Life is complete only for brief intervals in between toys or projects -- John Dalton
  104. Java is not faster than optimized c++ by cardshark2001 · · Score: 3, Insightful
    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.

    --
    WWJD? JWRTFA!
    1. Re:Java is not faster than optimized c++ by kaffiene · · Score: 1, Insightful

      (1) Do a google for "runtime optimisation"

      (2) Get a clue

    2. Re:Java is not faster than optimized c++ by Anonymous Coward · · Score: 0

      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?

      Yes.

      Suppose you only speak English, and the other person only speaks Chinese. It's probably going to be faster to use an interpreter than to look up everything they say in a dictionary and try and guess what they're talking about, right?

      (This doesn't disprove your point, but it does show that it's very hard to come up with a good analogy!)

    3. Re:Java is not faster than optimized c++ by iapetus · · Score: 2, Insightful

      If that's the approach you're going to take, though, then you might as well just code in assembly - cut out the middle man. Benchmarks like this are entirely worthless - the main thing they do is stir up the rabid language zealots out there, 5% of whom will be crying from the rooftops that it's all a lie and C++ is better, 2% of whom will be insisting that the results cast Java in a bad light and that it should be seventeen times faster than C++, the other 93% will be pimping their own language of choice.

      At the end of the day, the real question that I should be asking myself is which language gives me the best balance of maintainability, ease of development and elegance of expression. I don't care if you can shave two instructions from your generated assembly code at the cost of making your code ugly as hell and impossible to maintain. This is a bad trade-off that only matters to the most anal of benchmarkers and those rare few who really do need the absolute maximum performance from a (typically small) segment of their code. I want to know which language is going to make me most productive, and there's no objective measure of that which I trust as far as I can throw it.

      --
      ++ Say to Elrond "Hello.".
      Elrond says "No.". Elrond gives you some lunch.
    4. Re:Java is not faster than optimized c++ by Nightreaver · · Score: 0

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

      Well of course! Have you ever talked to someone who keeps rambling away about something that could have been said in a short sentence?
      As mentioned, runtime optimization is a possibility.

    5. Re:Java is not faster than optimized c++ by vadim_t · · Score: 1

      Nope, a compiled language is still faster. It's easy to explain:

      Runtime optimization analyzes the bytecode that's running and can come up with ways of optimizing things at runtime. However, this optimization was coded into the JVM, and there's absolutely nothing that stops you from emulating that approach in C.

      Let's say I have the function drawPixel(), which draws a picture on the screen. Inside it's got a switch statement, that selects different ways depending on the screen's bit depth.

      Well, the JVM might realize that we're always selecting 16 bit depth, and optimize that. Perhaps it will move the test for 16 bit to the first place.

      Now, in C we won't have that, but there's nothing stopping the programmer from coding a separate function for every possible bit depth, putting pointers to that function into an array, and selecting the right function to call during the beginning of the loop. Say:

      for(;;) {
      drawPixel = draw_pixel_functions[current_bit_depth];
      drawFram e();
      }

      There you go, a faster algorhitm in C. Code every version of drawPixel in assembler, and there's no way Java can beat that.

    6. Re:Java is not faster than optimized c++ by Anonymous Coward · · Score: 0
      The java compiler actually compiles to a virtual opcode format, which is then interpreted by the java virtual machine at runtime.

      If by "interpreted by the java virtual machine at runtime" you mean "compiled to machine code that runs natively", then yes. Otherwise, what you are saying is simply not factual. Using a purely interpreted virtual machine is one possible way to implement a spec-compliant JVM, but the fact remains that it is not actually how the real JVM works!

    7. Re:Java is not faster than optimized c++ by Anonymous+Brave+Guy · · Score: 1
      It's just not possible.

      That depends what you mean by "optimized C++".

      If you mean hand-optimised, by a perfect developer with infinite time available to effectively generate his own run-time framework, then perhaps not.

      If you mean the output produced by any contemporary optimising C++ compiler on realistic code, then I'm afraid you're rather behind the curve on compiler technology.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    8. Re:Java is not faster than optimized c++ by p3d0 · · Score: 2, Informative
      Runtime optimization analyzes the bytecode that's running and can come up with ways of optimizing things at runtime. However, this optimization was coded into the JVM, and there's absolutely nothing that stops you from emulating that approach in C.
      Wrong. JIT compilation offers you two things you can't get from a static compiler: (1) dynamic information about a particular run of the program, and (2) the opportunity to make optimistic assumptions, knowing you can re-compile if your assumptions are violated.

      Suppose that during a particular run, there is a particular variable x that, whenever we look at it, always has the value 42. Now we want to compile a method that uses that value. A JIT can optimistically assume that value will always be 42. Now it can go to town on optimizations involving that variable. Got an "if(x > 10)" statement? You can omit the compare and branch. Got a division with x as the denominator? You can omit the divide-by-zero check, and turn the divide into a cheaper multiply-by-reciprocal. And so on, and so on. Then, you register your assumptions with a runtime service that is capable of re-compiling the method of your assumptions turn out to be incorrect. If you ever see that variable with a value other than 42, you recompile it (and do some fancy footwork to deal with threads that might already be running the obsolete version).

      What you end up with is a method implementation that a static compiler just could not produce. Perhaps, if it were very smart, it could use profile-directed feedback to create a specialized version of the method for each of a number of "likely" values of x. However, unless you want to try to cover all 4 billion possible integer values, you must include a backup version for when you turn out to be wrong. Plus, you'll always have the overhead of choosing which of the specialized versions to call in the first place. This is all overhead the dynamic version doesn't have.

      So it is definitely not impossible for a dynamic compiler to outperform a static one. It is just very rare, given the current state of the art of compilers.

      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    9. Re:Java is not faster than optimized c++ by ParisTG · · Score: 1

      It is possible for dynamically compiled code to be faster than statically compiled code.

      Take for example HP's Dynamo project. Dynamo is basically an interpreter of PA-8000 code, but which runs on the PA-8000 processor itself. It's as if you were running an x86 emulator on an x86. Only that Dynamo was designed to dynamically compile and optimize the code it was interpreting. It turned out that the dynamically compiled code ran faster than the static binaries running on the raw processor in almost every case!

      True, they weren't running Java, but they were doing dynamic compilation. With a Dynamo based JVM for Java, I'll bet your task of writing C++ code which is faster in all cases would be quite a feat.

      More info on Dynamo can be found here.

    10. Re:Java is not faster than optimized c++ by Laxori666 · · Score: 1

      "Did he get down and dirty with the compiler and look at the generated assembly code? No, he did not."

      Did he get down and dirty with the Java compiler and look at the generated byte code? No, he did not.

    11. Re:Java is not faster than optimized c++ by cardshark2001 · · Score: 1
      At the end of the day, the real question that I should be asking myself is which language gives me the best balance of maintainability, ease of development and elegance of expression.

      Well said! I completely agree. That's basically what I was saying in my first paragraph. Java doesn't have to be faster to be better for a given task. Perl is the best choice for some tasks, and we all know how slow Perl is.

      However, when a computer science student takes some off the shelf code, and compiles it in Java and gcc, and comes to the conclusion that Java is faster, well, I just have to say something about it. I looked at his code, and the algorithms are implemented fairly naively. His idea of optimization is a *compiler switch*. Ha!

      Java simply cannot be faster than highly optimized c++ (with a good compiler, of course), any more than a pig could fly if you gave it wings. I'm sure you know that as well as I do. There's no magic going on in that virtual machine. At best, highly optimized Java could equal highly optimized c++.

      --
      WWJD? JWRTFA!
    12. Re:Java is not faster than optimized c++ by cardshark2001 · · Score: 1
      Suppose that during a particular run, there is a particular variable x that, whenever we look at it, always has the value 42. Now we want to compile a method that uses that value. A JIT can optimistically assume that value will always be 42. Now it can go to town on optimizations involving that variable. Got an "if(x > 10)" statement? You can omit the compare and branch.

      Are you saying that cannot be done in c++?

      Give me a break. It's called a constant. The precompiler replaces the tokens with constants before compilation. So in your example:

      #define LifeTheUniverseAndEverything 42
      if (x > 10) {...}

      becomes

      if (42 > 10)

      before the compiler even gets involved in the picture. When a sensible compiler sees "if (42 > 10)", it will not create a branching statement.

      I know my statement was pretty over the top. However, any Java advantages you can name could be themselves implemented in C++. Even if you are talking about self modifying code, that can be done in c++, it's just that usually self modifying code is not something you would do on purpose (although many people do it by accident :).

      Now, that having been said, I am perfectly open to the possibility that a naive implementation in c++ will be slower than a naive implementation in java for a specific algorithm. But when you say "optimized", there's a certain level past which you cannot optimize in java, whereas you can get right down to the nuts and bolts in c++, with some compilers you can get right down to the registers without even writing assembly code! Java is an extra layer of cruft that keeps you from the machine details, which is its major appeal ! Use it where it makes sense, where you need good cross platform compatibility, or you feel the design constraints are better fit to the task, or whatever your judgement tells you, but not because a comp sci undergrad took some off the shelf code and proclaimed it faster.

      --
      WWJD? JWRTFA!
    13. Re:Java is not faster than optimized c++ by cardshark2001 · · Score: 1
      if (x > 10) {...}

      Eh... my example should read

      if (LifeTheUniverseAndEverything > 10) {...}

      But you (hopefully) get the point.

      --
      WWJD? JWRTFA!
    14. Re:Java is not faster than optimized c++ by cardshark2001 · · Score: 1
      If you mean hand-optimised, by a perfect developer with infinite time available to effectively generate his own run-time framework, then perhaps not.

      Well, that is what I meant. I took issue with the idea that "optimized c++" means using the o2 switch in gcc.

      I should have made it clear that naive implementations in java vs c++ can be faster. I considered this to be obvious, and not related to the question of whether optimized code is faster. It cannot be, and I think you will agree.

      Does this mean it's always worth the effort? No, and emphatically no. Re-inventing the wheel is rarely a good thing, and if java comes with some kick ass runtime advantages out of the box that you would have to implement yourself in c++ to get the same performance, by all means, use java.

      The author just got my hackles up a bit.

      --
      WWJD? JWRTFA!
    15. Re:Java is not faster than optimized c++ by cardshark2001 · · Score: 1

      If you designed hardware to run java, well then java is native code, and likely nothing will be faster than java on that platform. This is fairly obvious, and hopefully it was fairly obvious in my reply that I was talking about a general purpose computer.

      --
      WWJD? JWRTFA!
    16. Re:Java is not faster than optimized c++ by cardshark2001 · · Score: 1
      If by "interpreted by the java virtual machine at runtime" you mean "compiled to machine code that runs natively", then yes.

      Well, that is what I meant. I realize that "interpreted" is a slightly loaded term and it was not my intention to set off your buttons. The fact remains that it is done at runtime, and the java opcodes are not native opcodes on a general purpose cpu, like Intel or AMD. As I've had to iterate to several other posters, I am certainly aware that a naive implementation of an algorithm could be faster in java than c++. That, however, is beside the point. Anything clever that the JVM does which is so great, a skilled c++ technician could also do.

      What language is the JVM written in, anyway? I don't know, but my guess would be c++. :)

      --
      WWJD? JWRTFA!
    17. Re:Java is not faster than optimized c++ by p3d0 · · Score: 1
      Are you being dense on purpose? I'm talking about a value the program gets from its input data at runtime. I think you should re-read my post with that understanding. (Boy, you really need to spell things out for some people.)
      However, any Java advantages you can name could be themselves implemented in C++.
      The difference is the presence of the JIT compiler at runtime. If you're talking about keeping some or all of the C++ compiler around while the program is running, then you're talking about a very unusual runtime environment. You'd be talking about JIT-compiled C++.
      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    18. Re:Java is not faster than optimized c++ by Decaff · · Score: 1

      It just can't be ... Okay, so how could I make a blanket statement like that?

      By not understanding how Java and JVMs work.

      The java compiler actually compiles to a virtual opcode format, which is then interpreted by the java virtual machine at runtime.

      No it's not. Except in very limited cases (such as embedded java, in restricted memory) this has not been true for a very long time.

      For a typical modern JVM, it goes like this: Java starts to interpret the bytecode. If a JIT system is used the bytecode is then translated into native machine code, which is cached in memory. If a Hotspot system is used, a separate thread profiles the program and when slow code is found, the JVM translates the bytecode into highly optimised native machine code.

      The machine code translators can be very thorough in their analysis, and can work out where it is safe to remove array bound checks etc.

      The reasons why Java can be faster that C or C++ are (1) the VM can determine precise details of the processor its running on, so that bytecode can be translated into machine code optimised for that processor, and (2) the VM can profile the application and dynamically optimise and re-optimise. With statically compiled programs the attempt at optimisation is done once only.

    19. Re:Java is not faster than optimized c++ by vadim_t · · Score: 1

      No, you're wrong again :-)

      JIT is not something magical that just the JVM can do. A C program can also do that, for example by generating code itself, modifying its own code, or using lots of pointers to functions. If you really wanted, you could even make your own mini-VM in C optimized for your application. But I doubt it's necessary to get that far.

      C also allows doing things that Java can't, like using specific instructions like MMX, and controlling memory allocation in a way that's optimal for your program.

      JIT might be able to do some nice tricks, but it'll probably never be as effective as coding the optimal algorithm for a task.

    20. Re:Java is not faster than optimized c++ by cardshark2001 · · Score: 1
      I guess I was being dense.

      However....

      The difference is the presence of the JIT compiler at runtime. If you're talking about keeping some or all of the C++ compiler around while the program is running, then you're talking about a very unusual runtime environment.

      If the JIT compiler really makes such a difference in performance as you think it does, don't you think that more of the top developers would use it? In your specific example, determining a loop invariant is not a free action. I hate to invoke Karmack here, but do you think that (just from a performance standpoint) Doom 3 could be written in Java?

      If your answer is yes, you are really deluding yourself.

      --
      WWJD? JWRTFA!
    21. Re:Java is not faster than optimized c++ by p3d0 · · Score: 1
      So what is your argument then? That a C program with a JIT compiler can be more efficient than a JVM with a JIT compiler? Fine, I yield, but I think it's highly misleading to say C is faster than Java for this reason. Java comes with a JIT compiler just by its very nature. Including a JIT compiler in a C program is unorthodox to say the least.

      Incidentally, there's no reason Java can't use MMX instructions. You have a point on controling memory allocation though.

      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    22. Re:Java is not faster than optimized c++ by p3d0 · · Score: 1
      If the JIT compiler really makes such a difference in performance as you think it does, don't you think that more of the top developers would use it?
      I can only reply by quoting myself...
      So it is definitely not impossible for a dynamic compiler to outperform a static one. It is just very rare, given the current state of the art of compilers.
      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    23. Re:Java is not faster than optimized c++ by cardshark2001 · · Score: 1

      But I never said otherwise. I said that optimized c++ would outperform Java, every time. This is different from compiler optimization. In that regard, I agree with you.

      --
      WWJD? JWRTFA!
    24. Re:Java is not faster than optimized c++ by cardshark2001 · · Score: 1

      (1) Do a google for "John Carmack".
      (2) Do I really need a (2)?

      --
      WWJD? JWRTFA!
    25. Re:Java is not faster than optimized c++ by ParisTG · · Score: 1

      Dynamo isn't hardware. Dynamo is the dynamic compiler/optimizer. They just happened to use the PA-8000 processors for the implementation since that's HP's own processor, so they might as well use it for their internal projects.

    26. Re:Java is not faster than optimized c++ by kaffiene · · Score: 1

      Right, so you're saying that every language other than C++ is irrellevant?

    27. Re:Java is not faster than optimized c++ by cardshark2001 · · Score: 1
      Right, so you're saying that every language other than C++ is irrellevant?

      Not at all. Different languages and compilers are best suited for different tasks. Performance is not one of Java's advantages, certainly not when compared to c++. That's what I'm saying. I'm all in favor of using the best tool to solve the problem. When it comes to cutting-edge performance, that tool is c++ (probably with some assembly code too).

      --
      WWJD? JWRTFA!
  105. OT - Maybe by Stevyn · · Score: 1

    This may be a little off topic, but why are linux programs primarily compiled with gcc? I've read how people complain how linux seems slower than windows. I've read people talk about how slow gcc is? I myself feel linux is slower than windows based on using windows and linux on the same computer. I use linux on my laptop and it's has a decent cpu so it doesn't seem to lag much, but the slowness is pretty bad on older hardware. So is gcc to blame and if so, is it possible for me to switch compilers and still run emerge on gentoo like I'm used to?

    1. Re:OT - Maybe by dmaxwell · · Score: 1

      Intel's compiler will work for some but not all of your software. You probably won't get away with compiling the kernel and glibc with it. I understand that there has been progress lately in increasing the compatibility of the Intel compiler and gcc.

      The main reason Linux programs are compiled with gcc is that code portability is valued more than it is in the Wintel world. For instance, I have virtually identical user environments on both my home P4 machine and my Powerbook at work. GCC has to produce reasonable code for at least 12 (maybe more) architectures. Intel and MS can optimize the hell out of the IA32/64 only cases. There is ongoing work to re-engineer some parts of GCC that go clear back to the mid eighties. But I seriously doubt a cross compiler will ever produce code as tight for a given arch as a compiler made specifically for that arch. Some code in the compiler is common to all arches. No x86-only optimizations will be made there. There are other parts that will be unique to each arch and I presume they will be doing what they can there.

      Even Apple and BSDs are using GCC. It is arguably to most important piece of software in the FOSS world. Thousands of projects have to compile to working binaries on cisc processors, 32/64/higher bits, and big and little endian machines. It is an extremely tough thing to get right and it can't be all things on all arches.

  106. SWT by Master+Of+Ninja · · Score: 2, Insightful

    But until it is bundled by default with the JVM and JDKs, it will still be hassle to get SWT working for normal users. If Sun replaced the swing toolkit with SwingWT and linked it to SWT, I would think there would be a great improvement in performance of most Java GUI apps (and most of them really do suck - the only good one I have seen is MoneyDance).

  107. Re:As usual... by Texas+Consultant · · Score: 0

    Offtopic? Please read the first line again.

  108. To borrow (and mutilate) a phrase from Satchmo by dtrent · · Score: 1

    If it feels slow, it IS slow....

  109. No dice by finkployd · · Score: 1

    Sorry, but I'm not taking the results of someone who looks like they learned everything they know about c++ from reading the comics in "C++ for Dummies" very seriously. Get a real c++ coder in there who doesn't do stupid, wasteful things with pointers and then maybe there can be a decent comparison.

    In other news, I can write a program in assembly that performs much worse than VBScript if I put my mind to it and make a bunch of stupid assembler mistakes.

    Finkployd

  110. In other news... by shihonage · · Score: 0

    ... John Carmack has updated his .plan with details about his next engine, codenamed "Mammoth". The engine features real-time raytracing and is written entirely in Macromedia Flash, which provides a level of performance superior to that of OpenGL.

  111. Re:Caught up with the speed, but still the ugliest by deputydink · · Score: 2, Interesting
    I couldn't agree more. I have been making a serious effort in the last few years to open my mind to technologies (like Swing) i had quickly dismissed earlier on.


    Apple's swing implementation is pretty fast, good looking, usable and well (but not *fully*, you have to implement your own Apple-W handlers and such, which is i guess to be expect) integrated with the host OS.


    Additionally, the support for JNLP/WebStart is very satifictory on both XP and OSX. A fine java deployment techonology that I believe is underrated.

  112. The performance hit is negligible... by bl8n8r · · Score: 2, Interesting

    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.

    --
    boycott slashdot February 10th - 17th check out: altSlashdot.org
  113. this is a joke by kendoka · · Score: 0, Redundant

    gcc doesn't exactly produce the most optimized code - guess he didn't know about that. Oh well - just another java freak trying to justify his poor coding skills. :P

    1. Re:this is a joke by kendoka · · Score: 1

      Hey I didn't think it was redundant - who said anything about poor coding skills or gcc? You moderators suck.. =)

  114. Re:Caught up with the speed, but still the ugliest by kaffiene · · Score: 3, Funny

    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.

  115. Re:This doesn't make any sense... by MetalShard · · Score: 2, Interesting

    If you are going to do that just make it run through and compile the entire thing in one shot rather than doing it a small bit a time. Then the end user won't have to experience the "just in time" part of the compile. I don't understand why if you can "just in time" compile it, you can't just compile it at build time and get it over with.

  116. The compiler by SteamyMobile · · Score: 1
    It's not just significant parts of the compiler that are written in Java. Sun's Java compiler is 100% pure Java. In fact, it is linked in to various other 100% pure Java apps such as Tomcat to compile JSPs. IBM has a Java compiler called Jikes that is written in 100% C or C++ (can't remember). The last time I used it, it started up much faster than Sun's javac, but I think that has changed now. Also, if you compile from within Ant, as most Java developers do, you only have one JVM startup time so the entire thing compiles very quickly. Again, Ant links in the Java compiler because it's all 100% Java.

    It's a much better idea to write a compiler in Java than in C. Compiler performance doesn't matter that much, but correctness does matter, and it's easier to write correct code in a clear object-oriented language like Java than C.

    1. Re:The compiler by Anonymous Coward · · Score: 0

      My C/C++ compiler and tools can be used to build themselves. When the JVM is written in Java (and works with any sort of speed), I'll look again.

    2. Re:The compiler by HFXPro · · Score: 1

      Well then we should be writing our our compilers in a functional language. Many run fast and are even easier to prove correctness of a running program.

      --
      Reserved Word.
  117. *Can* be faster by miyako · · Score: 1, Redundant

    I didn't RTFM, but from the headline, it seems like the word CAN is the gotcha, any language that has a purpose for existing can be faster than any other languages in certain situations. This is because computers are (generally) better at optomizing code than people.
    But, if this guy is saying that in general Java is faster than C++, I call bullshit. Don't get me wrong, I love Java, and there are a lot of great things about it, but speed ain't one of them.
    With the power of modern computers, java is generally fast enough, but if I'm writing an application to run on my 200mz ram hungry and already overloaded server, then Java is not going to be my langauge of choice.
    I wish people would just get over this programming language pissing contest that seems to have been going on, and promote each language based on it's own merits, and not try to say that any given language is the end all be all of programming.
    In my experience, Java is fast to write, and C++ is fast to run. C++ can be hard to debug, and Java can make it hard to eliminate overhead.
    If one day Java is faster than C++, Then I think it will have come at the expence at many of the things that java gets right.

    --
    Famous Last Words: "hmm...wikipedia says it's edible"
    1. Re:*Can* be faster by gnuLNX · · Score: 1

      Finally a post that makes sence. Quit the pissing contest.

      Besides most likely the fastest langauge to code with and run with is most likely the one that the coder is most familiar with.

      --
      what?
    2. Re:*Can* be faster by smileaf · · Score: 1

      true maybe java is faster at a few things. but IMO it can never load as fast as a C program.
      reason? A java VM must first be loaded.

      i read a post earlier that said that there is a VM that can run things faster. I say bullshit. if you can make an interpreter run code faster than native what are the chances of you just coding a native program that runs even faster than that? I think pretty high. reason being an interpreter must read the program then execute it. coding native you can just skip the interpret part.

      I love java. it's multi-platform and you don't need to compile it on 10 billions different systems just so everyone can use it.
      I hate java because everything runs slow. i'll stick to koffice before I'll go to openoffice.org. Why? koffice loads faster (and looks better, isn't better yet.. :) ).

      in every language you have a up and down. perl does regular expressions the best (IMHO), asm you can optimize it at a very low level, java multiple platforms.

      you can't really have a flame battle about what language is the best. there is no "best" language there is no 'fastest' language. it all depends on what needs to be done, the programmers experience with the language, the amount of time spent on the project and the compiler.

  118. different requirements by vlad_petric · · Score: 4, Informative
    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.

    --

    The Raven

  119. Quake2, Alien Flux, Tribal Trouble by maxgilead · · Score: 2, Informative

    Sure, there's java port of Quake 2, there's Alien Flux, Tribal Trouble. But, as others already mentioned Java is mostly used for programming game logic. It's performance is constantly improving and only recently it gained enough speed to be seriously considered for writing entire game engines.

  120. My brief tests seem to agree by Rhesus+Piece · · Score: 1

    Wow, who'da thunk it? I just gave some of his stuff a test run, and it looks like he's right. The JVM stuff is nearing 2x the speed of my G++3.3.3 stuff on some tests. I would like to see it tried with 3.4.1 or even the new 3.5 stuff, if possible. Anybody else do at home comparisons?

  121. Bull hockey by wurp · · Score: 2, Insightful

    If one program uses profiling information to run faster than another, it runs faster nonetheless. I agree with other posters that this is comparing compilation & runtime environments rather than languages, but when I care about how fast a program runs I care about how fast it runs, not how fast it would run in some hypothetical nonexistent environment. C++ would probably be faster if it had some kind of JIT environment to run in, but it doesn't, and as a developer trying to write fast software, that's what I care about.

    That said, I doubt the performance differences are enough to affect my decision about what language to use, unless I am writing some application that does enough computation that a person has to wait on the program, rather than the other way 'round.

    1. Re:Bull hockey by Anonymous+Brave+Guy · · Score: 1
      If one program uses profiling information to run faster than another, it runs faster nonetheless. [...] when I care about how fast a program runs I care about how fast it runs, not how fast it would run in some hypothetical nonexistent environment.

      But do you care how fast it runs the first time, or the second time with identical data?

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    2. Re:Bull hockey by wurp · · Score: 1

      I care about how fast it runs the hundredth time and onward with "representative" data, whatever that means ;-)

    3. Re:Bull hockey by Anonymous+Brave+Guy · · Score: 1
      I care about how fast it runs the hundredth time and onward with "representative" data, whatever that means ;-)

      Sure, if you're going to run code hundreds of times on similar data sets, it's probably worth the overhead of dynamic optimisation. The thing is, not much real code actually does that, and you need to be doing it a lot to justify slowing everything down by a significant factor because of the overhead of the profiling process. In your particular environment, I can see that there might be big wins, but for most people I doubt there ever will be, hence my suggestion that most of the talk about run-time optimisation is hype propagated by buzzword-a-holics.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    4. Re:Bull hockey by wurp · · Score: 1

      In fact, as with all profiling, all of this talk is BS - the only way to get a real answer is to profile in a real-world situation and see what happens. I don't have any data nor the time to do so, so we're reduced to opinion, and a difference thereof ;-)

  122. Computer vision by feelyoda · · Score: 1

    I must say that there is simply no way Java could be used for serious computer vision work, where I specialize.

    The need for speed is too great. Lack of memory-management optimization is the killer.

    Having programmed in Java for years, it was painful to give it up and switch back to C++ for performance reasons. Also, Intel's openCV library and other such C/C++ libraries are very useful.

    Also, in terms of ease of development (rather than speed), MATLAB has JAVA beat without question. I mean, if you are going with a VM, why not go all the way with an interpreter?

    I know of at least 3 companies that do heavy work in vision. Each have around 20 guys doing research in MATLAB and at least a dozen to translate it to C++ or C# to get it to run in real time.

    --

    Robo-Blogs of the world: UNITE!
    1. Re:Computer vision by kraut · · Score: 1

      Hear hear - if you're going to choose a language that's easier to develop in, why not go all the way and use a language that's really easy to develop in? Either a special purpose language, like Matlab, or R for statistics, or a general purpose one like Python.

      My main gripe with Java has always been that it's not much more expressive than C++ - in fact, it's actually less expressive than modern C++, and the only thing that rescues it are more comprehensive standard libraries

      --
      no taxation without representation!
  123. The methodology used here sucks by Troy+Baer · · Score: 3, Interesting
    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
    --
    "My life's work has been to prompt others... and be forgotten." --Cyrano de Bergerac
  124. Java is still pants... by Skiron · · Score: 0, Troll

    ... and always will be.

    Give me ONE good reason what java actually does right?

    You need one hell of a machine to run all the crap. It is still not fault tolerant to any degree.

    And seeing as it was initialy designed to run video recorders and washing machines, et al, why doesn't it now?

    Nick

    1. Re:Java is still pants... by fr0dicus · · Score: 1

      It seems ok on my cellphone....

  125. Re:This doesn't make any sense... by Anonymous Coward · · Score: 0

    The JITC uses profiling imformation from the app as it's running to make certain optimizations. That info's not available at build time, so the optimizations can't be made.

    The JITC process is generally 5% of overall runtime anyway, so it won't make much difference to the user.

    Might be nice if the JITC would save the optimizations it did make for subsequent runs, though.

  126. Geff K writes with more integrity by node159 · · Score: 0, Flamebait

    Honestly, the guy has no clue what he is doing, the numbers are completely meaningless. I mean here is my review with just as much scientific integrity:

    Test Results
    ------------
    Java: 30 GigaQuads
    C++: 3000000000000000000 GigaQuads

    Sumary
    -------
    Java: sux balls
    C++: is god

    I digress, back to reality now.

    None of the tests used any form of GUI testing, this is what the end user will mosty be dealing with so here it is, Swing is crap, its slow, ugly, and just a bad hack job. Eclips (the main opensource IDE) uses SWT instead of Swing to avoid these problems, for the uniformed, SWT simply does C calls to the OS to display the os's GUI library (this of course is at the expense of cross platform compatability).

    When it comes down to it a JIT compilere has the advantage of being able to optimize for memory size and what not, but then again JET compilers can spend all the time they want getting the code tweaked just right so its neither here nor there, even though experience has shown that the later tends to be faster as the system specs are generaly too similar nowdays (Umm try running java on a 16Mb machine :). And anyway, commonly used code is converted to native code if they are called often enough so other parts are mute aswell.

    In summary, JIT will always be a bit slowere because of the initial overheard, as for Swing, well thanks Sun you can have that pile of steaming shit back.

    --
    GPLv2: I want my rights, I want my phone call! DRM: What use is a phone call, if you are unable to speak?
  127. Are you fucking stupid Keith? by Anonymous Coward · · Score: 0

    I hate to attack you personally, but maybe you should think about a career outside of CS. Well-optimized C++ with *properly* written code HAS to run at least as fast or faster than any JVM. I've worked in the game industry for years and know what happens at the machine language level. In the end everything is machine code. The only way Java can run faster is if the C++ optimizer isn't doing its job (doubtful) or if the C++ code does stupid things (likely with CS students like you writing it).

  128. Re:Can I have an infinite budget to write the code by Anonymous Coward · · Score: 0

    Have you ever tried Qt?

  129. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 2, Insightful

    > By the sounds of it you have no idea what a good GUI is. Skins and themes do not a pretty UI make.

    Since Swing has all the GUI elements of every other toolkit, what would make a pretty UI if not skins/themes? A bad design can be done in any toolkit if the designer doesn't have a good sense of layout, etc.

  130. java methcall benchmark not making virtual calls by bgs4 · · Score: 2, Insightful
    Notice that the C++ methcall code declares "activate" a virtual function, but not so in the java version. No kidding you're going to get better performance.

    Presumably the java compiler inlined the function call. Do the math-- 4e9 function calls in 2.5 seconds. That's 1.6e9 function calls per second. On a 3.0 GhZ machine that's two cycles per call, so they're probably all inlined.

  131. Uhm... comment - by Anonymous Coward · · Score: 0

    Bwhahahahaha .ahahashah haah a ..
    oh wait .. there's more..

    BWhahahahahahahaha -gaha hahahaha .. who is the fucking moron that has obviously used neither language!!???

  132. it's reasonable by trance9 · · Score: 2, Insightful

    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.

    1. Re:it's reasonable by OldMiner · · Score: 1

      You can still take advantage of the '++' in C++. Sometimes the slower execution of using cout instead of printf() is due to cin and cout being tied. If I/O has to be done in a tight loop, it should go to a buffered, untied stream or be written to a string first. Stringstreams are useful things.

      It's important to know your language.

      Then again, why would you ever have a huge amount of console I/O in a tight loop? Oh, what was that? 'Artificial benchmarks'? And I thought this was supposed to be meaningful.

      --
      You like splinters in your crotch? -Jon Caldara
    2. Re:it's reasonable by cardshark2001 · · Score: 1
      -- Repeat: Some of you are simply religious.

      Well, the guy who posted this article wasn't exactly Charles Darwin.

      His idea of "optimized c++" is the -o2 switch in g++. Gimme a break!

      He took some off the shelf code and called it "optimized".

      His (and your) argument basically boils down to whether the naive approach in java can be faster than the naive approach in c++. Of course it can, but don't call it optimized.

      What language is the JVM for redhat written in?

      --
      WWJD? JWRTFA!
    3. Re:it's reasonable by trance9 · · Score: 1


      A good test of a compiler is whether it can take ordinary code and get good performance out of it. It's much less interesting to take optimized code and see how much more the compiler can optimize it.

      What you're basically saying is if I want to hand optimize every line of code I write, rather than concentrating on the task at hand, then I should use C++, but if I want the compiler to do the heavy lifting then I should use Java?

      OK--I've made my choice!

      Realistically each language has its place. The JVM is written in C because C is a good systems programming language. For a similar reason the kernel is written in C, and so forth. However that doesn't mean you want to write business logic of any kind in C--you don't.

      The question is then whether you turn to C++ or to Java or to some other higher level language.

    4. Re:it's reasonable by cardshark2001 · · Score: 2, Insightful
      What you're basically saying is if I want to hand optimize every line of code I write, rather than concentrating on the task at hand, then I should use C++, but if I want the compiler to do the heavy lifting then I should use Java?

      No, I'm not saying that at all. I'm saying Java can be faster, in some circumstances, if you are talking about a naive implementation. I never said that Java would always be faster, and I hardly think that is the case (some undergrad troll who made the front page of /. notwithstanding).

      However, when you need the utmost in performance, and second best won't cut it (and assembly is too much hassle), c++ is your best choice. Do you think Doom 3 could possibly be written in java? I'll answer that one for you - no way in hell. To suggest otherwise is ignorant and ludicrous at best, trolling at worst.

      --
      WWJD? JWRTFA!
    5. Re:it's reasonable by 0x0d0a · · Score: 1

      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.

      No overhead added by the JVM? I'll be impressed to hear about how you implement, say, polymorphism and reflection without some overhead.

      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.

      And the C++ compiler can perform optimizations that the Java one cannot because the Java one has to have certain runtime performance guarantees.

      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.

      Have you considered the opposite, that you might be fighting a religious war yourself? There are basically no horizontal-market Java apps despite years of Sun marketing, the few attempts at doing so have failed because of massive resource (CPU and memory) demands, promises of "faster performance with this *new* technology, really, this time" have been made over and over for years. I use the IBM JDK, currently the fastest JVM out for Linux, to run G2 GUI, a front end for mldonkey, and freenet. Both of these two programs run quite slowly and use a significant chunk of memory -- much more than my C daemons and front ends do.

      I agree that Java has the potential for certain performance improvements that C/C++ does not, but in the real world, Java really does significantly slower for reasonable tests.

      I've attended lectures in which I've heard distinguished language people break down performance issues with Java, and spoken with language people that have focused heavily on Java, and I'm reasonably comfortable with a claim that Java will not approach C/C++ performance for real-world tasks. Performance just was not a focus during Java's design. You can clearly see, looking at the featureset in C++, that almost no features that cause overhead were chosen, and those that were cause relatively minimal overhead. Java has a number of fundamental design decisons that cause performance hits (lack of generics (according to another post, which I have not yet verified, Java's 1.5 generic support is syntactic sugar and cannot be used for optimization), bounds-checking, heavy reliance on dynamic typing, a design that encourages frequent object creation and deletion, and so forth). Java was made to have a large number of whizz-bang features (which it does), have a strong set of functionality in the base language (which it does), be reasonably syntax-compatible with C++ to allow C++ coders to relatively easily use it (which it does). The strict observance of only adding features that induce compile-time overhead was not made (read a book on C++ or an ML variant and think to yourself how the compiler writer actually implements each feature -- there is a very strong emphasis on features that impose only such overhead).

      This does not mean that I think that Java is useless. I have written software in Java (by choice, where I had complete control over language choice) because it has a number of good points. I do *not* think that it is a C/C++ replacement (as many people have tried to bill it, and as Apple is trying to get people to use it). It just does not have an acceptable level of performance -- even if you have a fast computer, the user might as well be using the computer before his

    6. Re:it's reasonable by trance9 · · Score: 1


      If you want the utmost performance and second best won't cut it then we're talking about 0.001% of computing applications already, and we're probably talking about C, not C++. You won't be able to afford that extra pointer dereference.

    7. Re:it's reasonable by cardshark2001 · · Score: 1
      If you want the utmost performance and second best won't cut it then we're talking about 0.001% of computing applications already

      Yes, that's true, but the article that this thread is about made the (IMO outrageous) claim that "optimized c++" performed worse than java, when all he meant by optimized was a compiler switch (and probably the wrong compiler switch, at that). This is a far cry from demonstrating that java is superior to hand coded c++ optimization (which could even involve writing self-modifying assembly code).

      and we're probably talking about C, not C++.

      Nah. Usually with apps that require top performance, the engineers will optimize their inner loops, and maybe even add some assembly code (which, as I'm sure I don't have to point out - you can't do in java).

      --
      WWJD? JWRTFA!
  133. Broken Comparison, sorry folks. by Anonymous Coward · · Score: 0

    Quite rediculous-- the benchmarks do /not/ compare apples-to-apples at all.

    For one example, compare the Hash benchmarks. The C++ implementation uses a homegrown data structure, and algorithm, while the Java version uses a no doubt highly-optimized built in version.

    To be accurate, the benchmark needs to use explicit data structures and algorithms completely implemented in both languages.

    If you /really/ want to argue (I think wrongly) that since Java's got a built in hash type it should be used, at least then also compare a good STL map impelmentation.

    Additionally, although many of them are good, a number of the benchmarks for C and C++ at the Great Language Shootout can be improved (some easily, some with more work) with respect to their implementations. (One would assume that's probably true for other languages as well.)

    Anyhow, to compare A to B properly one must be measuring the same thing with the same units. The benchmarks presented here don't convince me that they do that.

  134. is it... by null-sRc · · Score: 1

    april fools day already? ... No.. ok well what's going on here?

    some sort of alternate universe i must have fallen into... :|

    --
    -judging another only defines yourself
  135. I Smell funny? by Bill,+Shooter+of+Bul · · Score: 2, Funny

    Well, you'd better tell your mom to switch perfumes.

    --
    Well.. maybe. Or Maybe not. But Definitely not sort of.
    1. Re:I Smell funny? by nizo · · Score: 1

      No thats mace you smell, not perfume. ;-)

  136. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    When you get out in the real world and begin working on real projects, you begin to notice when you are writing embedded code v. when you are writing an IDE. There is a time for C and a time for Java. Speaking from the real world, we use C for the embedded code and Java for the IDE. We don't even use assembly for embedded apps. When you are working with customers, deadlines, and cash, you too will stop caring about silly things like "respect for code".

  137. Re:Caught up with the speed, but still the ugliest by Photon+Ghoul · · Score: 1

    Sun needs to embrace SWT or make something better ( thats not hard )

    Cool!! Where's the web page for your implementation?

  138. Java -server always breaks micro-benchmarks by giliath · · Score: 2, Insightful

    The -server mode of java causes the JVM to recompile code for the most used code path. I have not looked at the exact code for each of the tests, but in many cases this can result in the JVM optimizing out the code completely. You have to be extremely careful when doing benchmarking of languages like java because the JVM is able to dynamically recompile the code to remove the actual work, if the results of that work are never used.

    ~Giliath

  139. Re:This doesn't make any sense... by Coppertone · · Score: 1

    The performance gain won't be as much as you would hope - remember your class files may change in between different invocation of the JVM, therefore checks will needs to be made to make sure those code segments are still valid - and that may be more work then it is worth.

  140. Client JVM Choices? by john_smith_45678 · · Score: 1

    'no one should ever run the client JVM when given the choice,'

    What choices are there?

  141. Deja vu all over again by Baldrake · · Score: 1
    Back in the late 80's when programming language research was much hotter than it is now, I remember reading many articles of the form "language x is faster than C". Prolog and Haskell were favourite examples. In both of these cases, the tests usually relied on inefficient tail-recursive C programs that could just as easily have been written using iteration. These papers were no doubt helpful in getting publications at Prolog or Haskell conferences, but didn't exactly represent an advance in human knowledge.

    As others have pointed out here, it's easy to write a program in your favourite language (in which you're an expert) and then translate it badly into C. No surprise about the resulting benchmarks.

  142. Re:Can I have an infinite budget to write the code by kaffiene · · Score: 2, Interesting

    I have two decades worth of programming experience, using most of the languages out there.

    I'm currently coding in C# (which sucks arse) and Java for object tracking in video. The Java code rocks - it's simple to write, it works and it's really fast. Video processing uses lots of loops with runtime constants which the hotspot JVMs seem to generate extremely fast code for.

  143. Retried Benchmark Results by Rhesus+Piece · · Score: 1

    I just did my own benchmarks for Ocaml, C++ (with O3, march, ftracer), and Java with the code for matrix, ackermann, and heapsort.

    In all 3, Ocaml came out fastest on my machine.

    Results:

    Matrix: G++ - 2.467s
    Java - 2.462s
    Ocaml - 1.062s
    Ackermann: G++ - 2.147s
    Java - 1.023s
    Ocaml - 0.603s
    Heapsort: G++ - 1.266s
    Java - 1.327s
    Ocaml - 1.116s

    (Note: the argument to heapsort was 1000000 and to
    ackerman was 11)

    I'm a wee bit surprised by this, but not much.

    1. Re:Retried Benchmark Results by andy314159pi · · Score: 1

      Matrix: G++ - 2.467s
      Java - 2.462s
      Ocaml - 1.062s

      Can you do these benchmarks with g77? Its a very strong GNU compiler.

    2. Re:Retried Benchmark Results by Anonymous Coward · · Score: 0

      Really?
      I read that Ocaml doesn't optimize when it compiles.
      This is pretty impressive that such a language can be faster, and be conducive to writing code with less bugs.

  144. You are eliminated the whole point of profiling. by SuperKendall · · Score: 2, Interesting

    Why is it "unfair" that Java is actually able to profile what is being run, vs. a static compiler having to guess? That is a very real advanatage of Java and should not be "leveled out" of the test. The benefit given by that technique is exactly what I would like to see.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  145. methcall results are just wrong! by Funkitup · · Score: 1

    c++ is almost twice as quick. Running his code!

    cslin185% g++ methcall.cpp -o methcall
    cslin185% time ./methcall 1000000000
    true
    false
    31.640u 0.000s 0:31.63 100.0% 0+0k 0+0io 200pf+0w
    cslin185% javac methcall.java
    cslin185% time java methcall 1000000000
    true
    false
    31.420u 0.000s 0:31.46 99.8% 0+0k 0+0io 1384pf+0w
    cslin185% g++ -O3 methcall.cpp -o methcall
    cslin185% time ./methcall 1000000000
    true
    false
    17.710u 0.000s 0:17.71 100.0% 0+0k 0+0io 199pf+0w

  146. Re:This doesn't make any sense... by Anonymous Coward · · Score: 0

    I believe this is what FX!32 used to do for running Win32 code on Alphas. Came out in the mid 90s IIRC.

    dmd

  147. add in C# for real comparrison by Anonymous Coward · · Score: 0

    use the java to C# then test java, c++ and C# side by side.

  148. Re:This doesn't make any sense... by Anonymous Coward · · Score: 0

    .NET already has this feature (so it does work for C#) You use a utility called ngen.exe to generate a native image which is then cached in the Global Assembly Cache.

  149. Maybe but... by JustinXB · · Score: 1

    "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." Go in with a slanted view, return with slanted results. Making Stuff Seem Like It Is Better Than It Really Is 101.

  150. Re:This doesn't make any sense... by Anonymous Coward · · Score: 0

    Caching the native machine code would compromise the security of the bytecode verification that happens when a class is loaded and before it is just-in-time compiled. The cached code could be edited in binary form to do malicious things.

  151. On the flip side by msgmonkey · · Score: 4, Insightful

    When C/C++ uses profiling it will only ever produce one "best case" compilation for a given function.

    With any JIT system you have the opertunity to use the profiling information from a given "window" of the execution so there is the possibility of having more than one compilation for a function.

    Now, I do not know how sophisticated JAVA JIT compilers have become but this is one area where JIT will have an upper hand over a static compiler.

    OTOH, these tests do not look like there is enough significant variation in the execution path for profiling to make a large difference.

    1. Re:On the flip side by Anonymous Coward · · Score: 0
      OTOH, these tests do not look like there is enough significant variation in the execution path for profiling to make a large difference.
      Oh, it makes a big difference. The matrix test app with 10000:
      C++ (after profile-arcs, branch-probablities):
      user 0m2.058s
      sys 0m0.002s

      Java:
      user 0m3.277s
      sys 0m0.011s
      Similar results with the other apps, esp. when made more similar (removing useless strdups in the hash test, e.g.).
    2. Re:On the flip side by sploxx · · Score: 1

      Simple solution. Use a VM (maybe the JVM) for C++. Whoosh, the problem goes away. As another poster stated: "Were' comparing compilers/VMs, *not* languages.".

      And, because you can go to lower levels with C++, I'll assure you that'll beat java every time you give it equal conditions.

  152. One more... by Rufus88 · · Score: 5, Funny


    anything else?

    Yeah, Kuro5hin is better than Slashdot.

  153. Re:You are eliminated the whole point of profiling by Anonymous Coward · · Score: 0

    In the real world, the developer would have run the profiler several times on his program and optimised it. Now we see Java for what it is - a tool to push the cost of what is normally development work onto the end user...

  154. The good ol' benchmark pissing contest... by l3ool · · Score: 1

    The last time I benchmarked Java vs. C++ myself, C++ came out on top overall but it was fairly close. However, that was using Java compiled to a native executable, no JVM was involved.

    Being primarily a C++ programmer I may be a little biased, but I can't see Java ever being faster than C++ and definately not JVM executed Java. Oh, don't get my started on C, in my own benchmarks Java got its ass whooped that's all I'm gonna say.

    I personally like both C++ and Java as tools, who cares which is faster? They both get the job done. *shrugs* Can't we all just get along?!

  155. I smell some BS in the CS by manthraxis · · Score: 1

    This is another case of a java fan skewing the statistics in javas favor. Of course by not using full optimization settings in the C++ compiler you can generate slower code than java.
    The fact is, if you know enough about how your C++ compiler compiles your C++ code you can make decisions about coding style that will ALWAYS produce faster code than java. Any JVM/JIT still doesn't know as well as the programmer what the app is trying to DO, and therefore cannot hope to achieve the level of optimization available to a human brain, except in some contrived cases where approximately equal performance can be achieved.
    REMEMBER: That JVM/JIT was written in C++ or some other similar pre-compiled HUMAN BRAIN optimized language no doubt. I can always drop into asm{} if i need that extra boost in my C++ app.. How can I do this in Java? Can't we all agree java is a great language and not get hung up on the FACT that it trades flexibility for speed, or trying to confuse the issue with meaningless statistics?
    It pisses me off that the java attitude seems to be that The Java Engineers have made a language that is so superior that you the programmer couldn't hope to make anything more optimal than what the JIT spits out.
    Also.. How can a JIT compile code fast enough to be Just In Time, but yet magically optimize the crap out of the code better than Intels C++ compiler churning through source files slowly one at a time and doing extensive analysis of how your algos work but doing it on the programmers workstation, instead of on somebodys 486 based webbrowser?... (thats Intel the CHIP MAKER who makes the CHIP that JVM is running on mind you.)
    The sad answer is IT CAN'T.

    Java is flexible for some applications and C/C++ is FASTER and sometimes less flexible for others. Get over it. Now once we get widespread adoption of native Java CPUs things may be different.. but until then, i'll keep lookin at the assembly when I want to be sure of what my code is doing on an x86.

  156. Re:This doesn't make any sense... by swillden · · Score: 2, Interesting

    I don't understand why if you can "just in time" compile it, you can't just compile it at build time and get it over with.

    You can, of course, and there are Java compilers that do (e.g. gcj). What this benchmark really demonstrates is that doing it may be suboptimal. Sun's JVM does something more than "just in time" compilation, it also does interpretation and profiling. The first few times a bit of code gets executed, the JVM will not just-in-time compile it, preferring instead to interpret the bytecodes and gather some statistics.

    After the same pathway has executed enough, the JVM will decide that it is a "hot spot" that will benefit from compilation to machine code. This compilation, however, will be performed with the benefit of the runtime statistics that were gathered while interpreting the code. Assuming that future executions will have characteristics similar to past executions (generally a reasonable assumption), the JVM will create machine code for what it knows is the typical execution profile.

    This profiling and late optimization is where Java gets the chance to beat pre-compiled code, after it's warmed up, anyway.

    Very good programmers who know their compilers and processors can do the same thing with compiled languages like C and C++. In fact, they can do a far better job because they have a better understanding of what the program does. However, that sort of optimization is hard work, error-prone, not very portable and interferes with maintainability.

    The JVM doesn't optimize as well as a good programmer, but it's a whole lot cheaper.

    --
    Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  157. My Hero! by 3770 · · Score: 4, Insightful

    No, I'm not being ironic.

    I'm tired of some programmers expecting to be worshipped because they know assembly.

    Assembly isn't all that.

    For some uses, it is the right tool. For 99.9%+ it most definitely isn't.

    --
    The Internet is full. Go Away!!!
    1. Re:My Hero! by HBI · · Score: 1, Interesting

      It's like knowing the classics. If you don't know assembly, you haven't a clue how the system works. Your optimizations will always be halfassed, since you don't know why things work the way they do.

      Someone who takes the time to learn assembly should be applauded, since the general trend has been to ignore it for greater and greater layers of crufty insulating toolkits and libraries to protect you from how the machine actually works. Two generations of coders beholden to API authors are the result. The current sexiness of virtual machines is another example of this. While HLLs and virtual machines are probably good for getting useful work out of people who otherwise wouldn't be willing to put in the time to learn how to code, your post is an example of why the HLL monoculture nowadays is harmful to the personal growth of today's coder. You probably dissuaded a few people who would benefit from learning how to do a few mov's and shl's.

      It seems to me you never considered it worthwile to learn assembly and are reinforcing the 'rightness' of your decision by crapping on those that have. You're wrong in any event.

      --
      HBI's Law: Frequency of calling others Nazis is directly correlated with the likelihood of the accuser being Communist.
    2. Re:My Hero! by 3770 · · Score: 2, Insightful

      I know assembly and I have studied CPU designs. I also know compiler technology and I have written a compiler (commercially).

      I abide by the rule "to write simple code and only optimize when needed" and it has worked great for me.

      I'm not crapping on those that know assembly, only those who think that it gives them a right to look down on those that don't.

      I stand by my rant.

      --
      The Internet is full. Go Away!!!
    3. Re:My Hero! by Hamled · · Score: 1

      While I certainly agree that knowledge of assembly (for the reason that it teaches you how the system actually works) is important, and anyone who wants to become a good coder should learn it... The 3770 is correct in that people who know it should not be revered and worshipped, because everyone should know assembly. That goes for people who mainly work with Java/.NET, they should learn Java Bytecodes and/or IL Assembler.

    4. Re:My Hero! by kfhickel · · Score: 2, Funny

      That's right, assembly isn't all that!

      learn microcode, then come and talk to me!!!!

      (yeah, I'm old, so what!) ;>

    5. Re:My Hero! by LoztInSpace · · Score: 1

      Absoultely!
      As an ex-assembly programmer in business applications (circa '87) I can say in this arena it's now virtually useless. I've certainly moved off it and have never looked back.
      Since then, more factors than speed contribute to a system's success, e.g.
      1) Maintainablity - #1 for a reason. This stuff will be around for years with an ever-changing staff to look after it.
      2) Extensibility - nothing stays the same and a good design will reflect this. There is often very little point in spending 100 hours optimizing a few specific cases that will be gone in a year.
      3)IO. Most of the stuff I write goes to a database. No amount of hand coded assembler will make my program go faster once I'm waiting for a database call to complete, which is can be several orders of magnitude longer than processing the result set.
      3.5) In the above cases, making use of a simple, safe threading model built into the language is better than attempting to write it faster in assembler.
      4)Use the database properly. Naieve database access is responsible for 95% of performance issues I've recently come across (application level joins/aggregation for example).
      5) An optimised or appropriate algorithm is often way better than an optimised implementation. For example, I've seen code iterating through some sort of list to find a value rather than using a map in the first place.
      6) In house, you can be pragmatic. If you have a well desgined system that underperforms it may well be cheaper to spend $1000 on a new box than a week of someone's time to rewrite or optimize in assembler, not to mention run it through the battery of regression tests, backout scenarios and all that other crap.
      7)Cross platform.
      Anyway - not to slag off assembly totally, but in the world of mainstream applications you're 99.9% correct with your 99.9%.

    6. Re:My Hero! by Anonymous Coward · · Score: 0

      "good god, is everyone on this website just full of shit or what"

      heh, uh yeah, duh

    7. Re:My Hero! by Anonymous Coward · · Score: 0

      Assembly isn't all that.

      For some uses, it is the right tool. For 99.9%+ it most definitely isn't.


      You're right assembly isn't the most used, but the algorithms and basic fundamentals is what is useful. There was a study a while ago that any decent (let alone good/great) algorithm or implementation was programmed from a person who knows assembly, they also comment more than likely they used these fundamental principles in their algorithm or implementation. So your right assembly might not be the right tool for the job, but without knowing how to use the most fundamental language you will never be great at a higher level language.

      My $0.02 again ...

    8. Re:My Hero! by Kosgrove · · Score: 2, Informative

      One of the most important reasons software has advanced is exactly BEACUSE of information abstraction - API's, object-oriented computing.

      In my experience, it's not a bad thing to be beholden to an API author. The author(s) likely know the system better than you. It's one of the things that helped humanity advance in general - specialization. It shouldn't be taken to the extreme, of course, SOMEONE has to know how the stuff works, but not most programmers.

      Assembly language is good to know, but many (most?) coders will not ever have a need to touch it, unless they are doing embedded design or compiler development. There are much more useful things to learn for those of us that write software. For example, I am absolutely shocked at the number of students who graduated with me that had taken a SPARC assembly class (required), but knew zero about relational databases. (Although to be fair to my alma mater, Penn State, I believe that situation has since been rectified.)

      By the way, I know assembly. MC68k as an undergraduate, a year of MIPS architecture as a graduate.

    9. Re:My Hero! by ThaReetLad · · Score: 1

      All optimisation is premature.

      If you write your code structures correctly then its a fair chance that a modern compiler like VC 7 or the latest intel compilers will produce either better or only slightly worse assmbly than an experienced assembly coder. OK you probably need to know a minimum of assembler to know and understand how to write good code structures, but 99.9% of the time hand coding is overkill and potential source of seriously evil bugs.

      --
      You can't win Darth. If you mod me down, I shall become more powerful than you could possibly imagine
    10. Re:My Hero! by Anonymous Coward · · Score: 0

      yes, it's a "troll" you dumbfucks

  158. Built-in Java? by LS · · Score: 1

    Ok, so I'll admit that I'm a C++ programmer and I don't know Java. I have a question. If all this profiling can make Java faster than C++ over the course of a few runs of the application, why can't a developer do all the profiling before hand, and then ship the cached code that was translated to machine code by the JVM as a native binary? Wouldn't you then have an app that doesn't require a JVM and would be faster than the C++ version?

    LS

    --
    There is a fine line between being a cultivated citizen and being someone else's crop. - A. J. Patrick Liszkie
    1. Re:Built-in Java? by taradfong · · Score: 1

      The JIT compiler more or less is doing just what you describe. From what I understand, it re-uses sections of bytecode that have been translated to opcode so that the JVM is minimally involved in code it has figured out is important and happens a lot.

      C/C++ is, really, standard shorthand for opcodes and binary files. The Java language is also a shorthand for bytecodes, but those bytecodes are helpless without a virtual machine.

      --
      Does it hurt to hear them lying? Was this the only world you had?
    2. Re:Built-in Java? by kaffiene · · Score: 1

      Some optimisations can only be done at runtime.

    3. Re:Built-in Java? by 09za+ · · Score: 1

      check out this guy's java games. A very hard doom type game and resizable racing game. They're both awesome examples [IMO(novice)]
      Brackeen.com

  159. Meaningless Question by Waffle+Iron · · Score: 2, Insightful
    There is no one answer to the question "which language is faster?". It all depends on that the workload is.

    For example, Java with its JIT can easily match a C compiler on bit-banging and number crunching small data sets when there's no memory allocation going on. However, that isn't what most people are waiting for when they run typical interactive applications.

    If a system is not I/O bound, most applications tend to be doing a lot of string manipulation or similar operations on small objects. When Java operates on strings, it tends to create, discard and garbage-collect a large number of short-lived string objects because Java's strings are immutable. This consumes quite a bit of CPU and memory.

    Some C++ applications are written the same way. Many KDE applications are rather sluggish, probably because they are taking advantage of a lot of automatic management of a lot of QT objects. STL-based C++ apps can also be sluggish if you use high-level containers like tree maps without a keen awareness about what kinds of extra copying and thrashing can happen under the hood when you use them. Even in C, if you use high-level libraries, you can get sluggish performance, as some of the more bloated Gnome apps demonstrate.

    However, C++ programs, even STL-based ones, may also be written in a different style that takes advantage of mutable strings and handles object allocation manually. This tends to reuse data structures in place, eliminating memory management overhead, and it has the very important effect of keeping caches and page tables much more localized. This is more bug-prone than the alternative, but can provide a substantial performance improvement that Java can't hope to touch on a similar dataset. The drawback is that the app is much more likely to crash unless it was written by a top-notch developer; in fact, this kind of programming is the cause of many of the security problems plaguing the various OSes over the years.

    (People often point out that nobody writes kernels in Java. That's because they tend to be written using the manual memory management style with as many static data structures as possible to squeeze out more performance. People don't use popular high-level C++ libraries to write kernels for the same reasons.)

    Bottom line, the answer to which language is faster will always be "it depends". It depends on what the program is doing, and it depends on how the program was written. A couple of datapoints from a language shootout don't help to resolve the issues.

  160. Ummm... by Anonymous Coward · · Score: 0

    Jackasses who start a conversation with "Ummm..." should be SHOT.

    1. Re:Ummm... by Anonymous Coward · · Score: 0

      Idiots who start a conversation with "Jackasses" should be trampled on by a herd of elephants chasing after Pink Fart Marcus wearing his wife beater and discolored FUBU shorts.

    2. Re:Ummm... by Anonymous Coward · · Score: 0

      Schmucks who start their conversations with "Idiots" should....

  161. Re:Can I have an infinite budget to write the code by Trepalium · · Score: 1

    Just because Athena/Xlib sucks doesn't mean AWT and Swing don't suck. If you want a toolkit for C++, then both WxWindows and Qt are wonderfully modern toolkits that are easy to write for. If you want Java toolkits, hopefully you skip AWT and Swing and target IBM's SWT instead. GUI toolkit is a really poor reason to choose Java. Choosing Java because you want the protection from buffer overflows, pointer corruption, and other common C programming mistakes is a good reason.

    --
    I used up all my sick days, so I'm calling in dead.
  162. Programmer productivity is a more important metric by StLawrence · · Score: 1

    I've heard that studies indicate that programmers who write their code in Java are 2 to 10 times more productive than those who use C/C++, but I can't find pointers to those studies right now. Anybody got some references?

    I any case, I think it's probably true, speaking from firsthand experience. I programmed for more than 15 years in C/C++, and now that I use Java, I pray daily that I'll never have to write another line of code in C/C++. With Java, things often work the first try and just don't break. With C/C++, I've found that latent bugs can lurk in the code for years before they're tracked down and fixed.

    Of coures it is possible to write good code (or bad code) in any language. But clearly, with Java, it's a lot easier to write good code. Java is much simpler than C++, and much less dangerous than C.

  163. Re:Can I have an infinite budget to write the code by swillden · · Score: 3, Insightful

    Unix GUIs are far easier to implement with Java than with C++. Athena/Xlib are a huge fargin' hassle and no-one ever gets the widgets right. Motif is too expensive to license.

    You really need to look into Qt. It's much easier to use than Swing.

    --
    Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  164. Re:Caught up with the speed, but still the ugliest by braindead · · Score: 2, Interesting
    • P.S: yes i have seen beautiful swing apps, yet they look out of place.
    I guess it's a matter of taste. You may prefer that your java app looks the same as the other apps around it at the time, but I prefer my java app to look the same on my windows machine and on my linux machine.
  165. Java is not under one vendor!!!! by SuperKendall · · Score: 4, Insightful

    You are once again spouting the tired old line that Sun is the master of Java. Not at all true, Java's fate is controlled by a whole host of companies - including IBM. Take a look at the reality of Java platform evolution at the Java Community Process web site.

    It's a standards body just like any other, just more open.

    P.S. - Aside from that gripe being wrong, I agree with the other poster that you should look into Objective-C to address other issues. Look for "GnuSTEP" for cross-platform objective C GUI work. It's just nicer to use on a Mac as they have very good tools (though in fairness I have never looked at what GnuSTEP tools might be around, I just can't imagine them being quite as good as the tools Apple has sunk so much effort into!).

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  166. Converting C++ apps to Java by Anonymous Coward · · Score: 0

    Couple of apps that we converted from C++ to Java are MUCH faster in Java version. Some design changes undoubtedly have contributed to the increased performance but Java being fast also helped.

  167. Re:That's what happens with the lowest common GUI by Anonymous Coward · · Score: 0

    Actually, no. Show me the Perl/Tk app that looks normal, fast & pretty on OS X.

  168. Re:my arse by sjf · · Score: 1

    Not quite true. Look at the branch prediction instructions in RISC architectures. They pretty much allow the instruction pipeline to ignore the 'loop if test isn't met' instruction.

    -s

  169. stinking BS by Anonymous Coward · · Score: 0

    the java is a nice little tool for bad coders, who have difficulties with the concept of pointer

    I also found that it's prefered by a greater percentage of women, but it should be verified.
    Comments ?

  170. It's the STL that is slow, not the language by jay2003 · · Score: 1

    Looking at the benchmark code, the C++ code uses the STL extensively. The STL is slow and bloated. The standard Java class libraries are much better designed and written and I'm not surprised with a good JIT compiler, java beats the STL for speed.

  171. Agree, Java can be great with a little profiling by SuperKendall · · Score: 2, Insightful

    I had similar experiences writing a Swing app around six years ago (just around the release of 1.2). At first the Swing app was a little slow, but after a number of rounds of profiling and tuning it was really, really fast - with an MDI interfance and a lot of heavily customized controls on very busy forms. The app worked great even on slower computers, and was well received by the client.

    There is no reason Java has to be slow. It's just prone to having a lot of layers stuck on things when they might not need to be. As you say, for a lot of work people are doing J2EE stuff may well be overkill (though even that can work with simialr efforts to tune).

    Basically, with any VM app tuning is key. As C# people are only just now starting to realize... a shame the tools there are a lot more primitive that what Java has to offer.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  172. The main flaw of such benchmarks... by WARM3CH · · Score: 2, Interesting

    is not just using the right compiler and right options, but the bechmark codes they use. Just look at this bench mark, are they really C++ codes? Are they the type of the codes that pushes the programmer to use the most advanced techniques? I for one, use C++ because of Boost, because of Blitz++, because of not having a garbage collection mechanism. Why these benchmarks never use a code to calculate some really challenging processing like a series of operations on large matrixes of complex numbers? Why they don't try benchmark where you have to allocate and free a large number of nodes in a large scale graph traversal and coloring program? Why they don't try to see how ESPRESSO performs in C++ and Java? How about large scale FFTs? Raytracing? Finite elements? JPEG compression and decompression? You can get any results you wish in comparision of any two languages and implementations as long as you don't write even a single routine of real-world code.

    1. Re:The main flaw of such benchmarks... by serviscope_minor · · Score: 1

      That is, they use C++ features like the iostream stuff (cout, and friends) which is extremely slow.

      If you're finding iostreams (especially the GNU implementation of cin/cout) very slow, try doing

      cin.sync_with_stdio(false);

      For some reason, keeping in sync slows things down a lot on GNU systems.

      --
      SJW n. One who posts facts.
  173. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    you are right of course. i just hate themes and must say so at every available opportunity. i have nightmares about living in a world where every single piece of software on my computer can have a theme applied to it. hold me.

  174. Good point... by SuperKendall · · Score: 1

    That's a good point though I somehow imagine that's not quite what the poster has in mind. It's not exactly a mind-blowing demonstration of graphical prowess, even if it was a great game...

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  175. Re:Can I have an infinite budget to write the code by Anonymous Coward · · Score: 0

    C# sucks, but java rocks? Gee, your bias doesn't show much. They're almost exactly the fucking same.

    Oh, no, I forgot... C# is a Microsoft technology - that makes it worse.

  176. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    I believe the inferrence was that Sun could hardly create something worse than Swing, not that the poster him/herself finds the task of creating a UI toolkit implementation to be "not hard".

    I strongly advise acquiring the ability to read.

  177. Re:Caught up with the speed, but still the ugliest by frodo+from+middle+ea · · Score: 1

    Didn't the reimen hypothesis prove this ? Or did I miss any thing in that apology ?

    --
    for the last time people, I am "frodo from middle eaRTH", not "middle eaST".
  178. shenanigans by Anonymous Coward · · Score: 1, Interesting
    From the original site:
    Method Calls
    Measurement of CPU as N varies
    100000 400000 700000 1000000
    1. se 0.01 0.02 0.04 0.05
    2. g++ 0.01 0.03 0.05 0.07
    3. gcc 0.01 0.04 0.06 0.09
    ...
    11. java 0.56 0.62 0.68 0.74
    Note that G++ is in 2nd place and is 2.25x faster than Java ((0.74 - 0.56) / (0.09 - 0.01) = 2.25), which comes in 11th overall.

    However, the new guy gets:

    Times (smaller is better)
    G++ 3.3.1 Java 1.4.2
    Intel 386 Intel 686 Server JVM Client JVM
    ...
    Method call 24 20.49 2.47 39.18
    Somehow this new guy's tests conclude that Java is 10x faster than C++ in the exact same test? I call shenanigans.
  179. The speed of java is only one concern by adiposity · · Score: 3, Insightful

    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

    1. Re:The speed of java is only one concern by drew · · Score: 1

      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.

      i think the actual explanation is closer to the first explanation- namely, all java GUI programs use poorly implemented GUI libraries. I know java can perform admirably as a server language, but up until recently, I had never used a java GUI application that was not a) slow, b) ugly, c) a royal PITA to use, and d) slow.

      I have had to change my stance on that statement recently, having spent a decent amount of time lately using the Zend Development Environment for PHP, which is written in Java. In this particular case the java GUI is a) slow, and b) slow.

      --
      If I don't put anything here, will anyone recognize me anymore?
    2. Re:The speed of java is only one concern by linhux · · Score: 1

      SWT and SWT-based applications adresses some of your conserns. Check out Azareus, for example, a very good BitTorrent client written in Java, which to me is pretty much equal to most Windows applications in responsiveness.

      SWT is a native GUI toolkit for Java (available for many different platforms), so it has the advantage of being able to take advantage of whetever platform-specific goodies there are.

  180. Re:Can I have an infinite budget to write the code by lokedhs · · Score: 1
    SWT is really a pain in the arse to code for compared to Swing. The main reason SWT was developed was to create a higher performance low-level UI for Java.

    Unfortunately, SWT is a pig these days. Like I said, it's terrible to code for and since Swing is actually faster than GTK+ now, there isn't much reason to use SWT.

    Show me a developer who use both SWT and Swing who still prefers to use SWT. If they exist, they are very rare.

    Oh, and of you really want to use the GTK+ widgets in Java, there's a much better project, the JavaGNOME project.

  181. Hitting the crack pipe again? by Anonymous Coward · · Score: 0
    That's especially easy on a hyperthreaded system. 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.)

    You believe everything Intel tells you?? It's not free, becuase it's another thread banging on your memory (esp L2).

    And even if it was "free" there is still an opportunity cost - some other thread (not your program's) could be running as well.

  182. Re:Can I have an infinite budget to write the code by Sebastopol · · Score: 1

    But Qt ain't free. ;-)

    (unless there's a freeware/OSF version??)

    --
    https://www.accountkiller.com/removal-requested
  183. Re:This doesn't make any sense... by lokedhs · · Score: 1
    The class libraries are also poorly designed
    I find this statment very strange. Even the most extreme anti-java people usually agrees that if everything else sucks, at least it has an amazing class library.

    I can agree that there are some stupidities in the class libraries, but there are no standard class libraries for any language that even comes close.

  184. Cross platform by Psymunn · · Score: 2, Insightful

    C++ is as cross platform as the libraries you use. The game code i'm writing so far (it's a simple game, doesn't have any assmebly or optimisation... just a keen like side scroller) compiles under both windows and linux. Using the same make file. How? I use SDL for everything. I've had equally pleasent experiences with Qt. Portability in C and C++ is all based on the libraries.
    Of course being able to compile on multiple platforms and being cross platform aren't the same thing but I still think that it is in the benefit of people producing software for Linux specifically, to write code that will port to Windows without to much avail (who the hell uses \?)

    --
    The Neo-Bohemian Techno-Socialist
  185. So many sucky java apps by Anonymous Coward · · Score: 0

    They are slow, they leak memory, they crash.

    Yeah, go ahead, blame the JVM.

    Sure, it is nice to get apps under Linux that would otherwise be Windows only... But it is far from ideal.

    Sorry, but as a user I dread java apps.

  186. Re:This doesn't make any sense... by Anonymous Coward · · Score: 0

    Then cache it where only root and/or the special java user can edit it. Practically it isn't a problem if each user keeps his own cache since it will have to pass through the bytecode verified to get to the cache and if the user wants to scribble on his own files, he doesn't have to gets so complicated as to dork with his java cache, he could just type "rm -rf ~" and be done with it.

  187. Re:Can I have an infinite budget to write the code by gnuLNX · · Score: 1

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

    Sorry but when you use 4 engineers for 6 months you can't claim no to little effort.

    --
    what?
  188. MOD PARENT UP. by Anonymous Coward · · Score: 0

    Funkitup's benchmark agrees with the original site's results (and substantially discredits the new guy). See my post calling shenanigans on the new guy.

  189. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    No, the worst thing about Java, IMHO, is classpath hell.

  190. I just don't see the point... by KnacTheMife · · Score: 0

    It's comparing a language using a static compiler
    to a language using run-time compiler. How is comparing two different types of compilers going to provide a useful comparison of languages? Until I see a study of JAVA on a JVM compared with C/C++ on a comparable run-time compiler I think these benchmarks are pointless. I thought engineering was about design and choosing the right tools for the job, not learning a single tool and shouting "It's the Best For All Your Needs!".

    As a side note, from TFA:

    "The results he got were that Java is significantly faster than optimized C++ in many cases."

    That says many cases, not a majority of cases and damn well not all cases. OH NO! A newer language has advantages in certain cases! "I think I'm going to have a heart attack and DIE from that surprise!"

    --
    -- "Someone's gotta go back for a shit-load of dimes."
  191. Re:java methcall benchmark not making virtual call by Anonymous Coward · · Score: 0

    Uh, Java methods are virtual by default.

    The better jits (e.g. HotSpot server) can inline virtual methods at runtime, but that's a fair optimization. No static C++ compiler can inline virtual methods.

  192. Re:Can I have an infinite budget to write the code by Anonymous Coward · · Score: 0

    c# has fucking xml gobbledegook interspersed with C++/Java style code. C# has NO CHECKED EXCEPTIONS (this alone meant it was discounted in my employer's enterprise business boring-as-hell-but-vital apps). Java and C# are going for the 21st-century-COBOL market, and Java is a better COBOL than C#.

    I can understand someone thinking Java was better than C# despite their broad similarities.

  193. Re:A few points... (matrix multiplication in C++) by Anonymous Coward · · Score: 0

    The matrix multiplication was implemented very poorly in C++. First, the matrices are constructed as arrays of pointers (to facilitate passing between functions--C++ is bad at this, modern fortran is *way* better). Then, the inner loop of the multiplication is
    for (k=0; k<cols; k++) {
    val += m1[i][k] * m2[k][j];
    }
    so that a different pointer must be dereferenced each time m2[k][j] is accessed. In short, transposing m2 first (an O(n^2) operation) would dramatically improve performance.

  194. He's an idiot - get the facts. by Anonymous Coward · · Score: 0

    The poor chap is obviously intellectually challenged if he can't debug some C or understand the gcc errors. The comment I find most amusing is this: "The test was creating a new StringBuffer in each iteration of the loop .... I updated the code to use a single StringBuffer and appending to it inside the loop."
    Modern Java JITs (2001 onwards) optimize this particular bottleneck and best programming practises recommend you minimise variable scope as much as possible, that means declaring it in the loop. Sure the original Java runtime environments (pre hotspot) would redeclare the string buffer in every iteration but not in Java 2! I did have an article on this but I can't find it so please make do with this and this.
    I think we can safely ignore his results until we have a real professional with an actual degree look this over.

  195. Re:I call shenanigans by Anonymous Coward · · Score: 0

    I'm sorry but there is

  196. Quick analysis... by the_skywise · · Score: 2, Informative

    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.

  197. Makes Sense by Queer+Boy · · Score: 1

    In theory, optomising C++ compilers is done for processors, whereas JAVA optimisations are done at the OS level. Makes sense to me then that JAVA would be faster with the amount of effort put into it to make it run faster.

    --
    Not since Marie-Antoinette played milkmaid has looking simple and honest been so fake and complicated.
  198. Is it faster? by areve · · Score: 1

    it could be faster and i've read a few articles that show how. Others have done similar testing too I'll be pleased to see java implemented but I still love perl and a bit of gawk. see lots of here language benchmarks - I really like this site.

  199. Explanation by gillbates · · Score: 4, Interesting

    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.

    --
    The society for a thought-free internet welcomes you.
    1. Re:Explanation by areve · · Score: 2, Informative

      java is JIT compiled not interpreted

    2. Re:Explanation by gillbates · · Score: 1

      Oops.

      I knew Sun had been talking about HotSpot for a while, but I didn't know if they actually had a release yet.

      Well, in that case, I'm kind of surprised that Java didn't do better than it did. It seems to me that Java is more lightweight than C++.

      --
      The society for a thought-free internet welcomes you.
    3. Re:Explanation by areve · · Score: 1

      I'm a sceptic though I, like others, find it hard to believe this article... so it's news on slashdot.

    4. Re:Explanation by kaffiene · · Score: 1

      Hotspot JVMs have been out for years.

    5. Re:Explanation by neurojab · · Score: 2, Informative

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

      It's a bit simplistic to call Java an "interpreted" language. A Java source file is compiled into bytecode. Modern JVMs then take this bytecode and use a Just In Time compiler to compile it into machine code just before it runs. Naturally this is a bit of overhead up front, but once the class is JITed, it will perform on the order of natively compiled code written in another language.

    6. Re:Explanation by korvus · · Score: 1

      Ok, just because I've read this mistake over and over again, I feel a need to correct it. The "client" and "server" VMs have NOTHING to do with things being run on the "server" or "client". The names come from the fact that the "client" VM is designed for normal user applications where startup time is a major factor. The "server" VM is designed for applications (like servers) that run longer and thus can trade off startup time for more optimized execution. It's kind of like making space-speed tradeoffs in g++ since using a LOT of space may slow down startup while the OS swaps things to disk and whatnot but it runs faster once its loaded. That being said, I think the g++ benchmarks should have used -O3, but I guess the real point that I see is that you aren't necessarily shooting yourself in the foot performance-wise if you use java instead of c++.

    7. Re:Explanation by MemoryDragon · · Score: 1

      Not quite true either. The java VM is quite sophisticated. First it compiles via a JIT compiler the native code into the platform code. But secondly and much more important, it does a statistical runtime analysis of the code it runs and optimizes it during runtime. You can see that effect very often with java programs gaining almost 100% more speed within the first half minute or minute of execution. Dynamic inlining and other optimization methods java starts to perform at that time give a huge speed boost.

    8. Re:Explanation by gillbates · · Score: 1

      For the sake of brevity, I assumed that a developer would be using the -server switch for development; since -client is the default, he'd either have to instruct his users on how to configure Java, or risk a slow runtime.

      There's also the possibility that older JVM's may not perform as well as his development one...

      --
      The society for a thought-free internet welcomes you.
  200. previous publications on the same topic by wdebruij · · Score: 1

    I recently read a PhD dissertation discussing (among others) a java-based grid environment. At first the entire idea sounded odd to me because of an expected performance drop. However, cases where java can be as fast as and sometimes even faster than optimized C have been shown before.

    In the dissertation, two papers are mentioned that compare java to C and apparently show positive results for java. I haven't actually read these papers, by the way. However, their titles suggest that they might be on-topic here.

    The first is "Benchmarking Java against C and Fortran for Scientific Applications" by J. M. Bull, L. A. Smith, L. Pottage and R. Freeman

    Second, and judging from its title perhaps less on-topic is "High-Performance Java Codes for Computational Fluid Dynamics" by Christopher Riley, Siddhartha Chatterjee and Rupak Biswas

    finally, the dissertation can be found on Rob van Nieuwpoort's publication list and is titled "Efficient Java-Centric Grid-Computing"

    As citeseer is always crawling, even without a link on slashdot, I was afraid to post this... but then I remembered that noone here actually reads the FM :) Jokes aside, it is a great resource and I hope that they get some mirrors soon.

    1. Re:previous publications on the same topic by andy314159pi · · Score: 1

      If anybody is interested in what the first article says, you could sumarize it as follows:

      Fortran smokes Java and is still faster than C.

      Fortran is the mother of all computer languages.

  201. Study Might Be Flawed by xp · · Score: 1

    I find it disingenous that the story does not mention the C++ compiler that Java was compared against (nor the Java compiler).

    C++ has some really poor implementations. For example, in Kernighan and Pike's "The Practice of Programming", C++ comes out slower than Perl for their application.

    The non-story here might be: Really Good Java Compiler Beats Really Bad C++ Compiler.

    ----
    Notes on Stuff

    1. Re:Study Might Be Flawed by Anonymous Coward · · Score: 0

      GCC vs Suns Java.
      The actual version number is given in the FA.

      So... RTFA!

    2. Re:Study Might Be Flawed by KnightStalker · · Score: 1

      Huh?

      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.

      Cut'n'pasted for your convenience. It's the second paragraph.

      --
      * And remember, it's spelled N-e-t-s-c-a-p-e, but it's pronounced "Mozilla."
  202. LEA! LEA! The guy's name is LEA! by fizzup · · Score: 2, Interesting

    LEA was "Load Effective Address" for the 8086, and it was a fast (and obscure, sidey-affecty) way to speed up a certain set of multiplication (and combo multiplication/addition) operations, which I now forget. Where's Abrash when you need 'im?

  203. Re:Can I have an infinite budget to write the code by kaffiene · · Score: 2, Interesting

    Almost exactly the same?

    C# doesn't have checked exceptions.
    C# allows the use of pointers.
    C# has pass by reference.
    C# has one major IDE (Visual Studio) which has a RAD philosophy which *does* prevent some valid C# code being written.
    C# has properties a-la Delphi
    C# isn't portable.
    C# has a bitmap class which is as slow as hell compared to the Java equivallent.
    C# has operator overloading
    C# doesn't have inner classes that can access the members of their container clases
    C# doesn't have anonymous classes
    C# has delegates

    There's just the differences I could pick off the top of my head.

    A lot of the really significant differences aren't in the core language (though there are a few of those, which mainly strip back the safety and simplicity that Java provides) but in the libraries and IDE.

    The IDE is really buggy and it forces RAD concepts on the programmer (shades of Delphi) which is a pain in the ass if you want to concentrate on code.

    There are *plenty* of reasons to like Java and not C# - they are *not* "exactly the same"

  204. Re:Can I have an infinite budget to write the code by ByteSlicer · · Score: 1

    WxWindows is called WxWidgets nowadays. wx4j is a binding of WxWidgets for Java, and is similar to SWT. Still in first stages of development, though.

  205. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    You must be new here. Ever used a TCL app? Or any native Unix app that uses Athena widgets? Or even just plain Motif?

  206. Bleeding Edge 3D Graphics In Java by CHaN_316 · · Score: 1

    Here's a game who's graphics will blow you away and settle this once and for all, Java can be used when performance is REALLY needed. BEHOLD! The ultimate 3D java MMORPG game, Runescape! Screenshots here.

    :P

    --
    "There is no spoon." - The Matrix
    1. Re:Bleeding Edge 3D Graphics In Java by Ex-MislTech · · Score: 1

      LOL, Runescape, I have seen better graphics on the Atari 800 .

      Peace !
      Ex-MislTech

      --
      google "32 trillion offshore needs IRS attention"
  207. Optimization at runtime vs. compile time by Get+Behind+the+Mule · · Score: 4, Insightful

    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.

    1. Re:Optimization at runtime vs. compile time by cant_get_a_good_nick · · Score: 1

      I forgot the model number, but some HP PA_RISC chips essentially did runtime optimization. Much like Pentium class and higher chips decode x86 ABI calls into micro-ops and feed to a more RISC-like core, I thionk the 8800 decoded RISC ops to RISC ops, but reordered and optimized them. Since you're going from RISC to RISC, you don't have the immense decode logic, nor do you have to worry so much about deep pipeline stalls and clears that you get with the new Pentium 4s. You're able to reorder based on current chip state, and I think this dynamic recompilation resulted in something like a 30% improvement. Sadly, and ironically, this is the last chip in the PA-RISC like which was scuttled for Itanium, which takes essentially the reverse view (push more and more optimization into the compiler) and has had pathetically slow roll outs.

    2. Re:Optimization at runtime vs. compile time by Anonymous Coward · · Score: 0

      Intel's C++ compiler and the next version of Microsoft's support Profile Guided Optimizations. No, you can't optimize for one specific run, but you can optimize for the common case across many runs. That means that that time consuming function will be as fast as possible the first time through rather than the fifth. All without manual tweaking.

      Sure, it's possible that interpreted code could be faster, it's just not likely in the long run.

    3. Re:Optimization at runtime vs. compile time by cardshark2001 · · Score: 1
      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.

      Err.... what language is the JVM written in?

      I'd guess it's written in c++. And if it isn't, you certainly could write it in c++, don't you agree?

      Now, have you really thought this out?

      No one is saying a naive implementation (like the ones this guy posted) cannot be faster in java than c++. However, when you say "optimized c++", that does not mean g++ with the -o2 switch. That means you optimized the code.

      Any Java-specific advantages you can name could themselves be implemented in c++. Would it be a good idea to do so? Probably not. If the tool is the best for the task, use it. Just don't give us this crap about "optimized code", when all you mean is you told the compiler to do its best with a naive implementation.

      --
      WWJD? JWRTFA!
    4. Re:Optimization at runtime vs. compile time by Get+Behind+the+Mule · · Score: 2, Insightful
      Now, have you really thought this out?


      Sure have, friend, so let me respond with another question: Did you read my post? It seems that you've completely missed the point.

      First of all, I wasn't talking about Java and C++ so specifically, but rather about running byte code on a virtual machines vs. running machine code directly. When the VM is running byte code, it can profile the actual behavior of the program and optimize the sections that really are the slowest. A compiler that translates to machine code cannot do this, it can only guess at the best optimizations.

      Let's turn the languages around. Suppose we write a VM in Java, which runs byte code compiled from C++ programs. Then it can profile the running C++ byte code and optimize the critical sections. A C++ compiler that translates directly to machine code cannot do that.

      Understood this time?

    5. Re:Optimization at runtime vs. compile time by Anonymous Coward · · Score: 0

      Well that sounds like a Fanboy talking.

      Can you be a little more specific about these magical runtime optimizations a JVM can perform? Because I'd like to know exactly what it does and what is _actually_ implemented by current JVMs. I mean is hot-path optimization actually implemented by any JVM? And if so, what's the overhead? Because that's something that never seems to get mentioned is what the overhead is of runtime optimizations.

      So given the overhead of runtime optimizations, the relatively small size of the benchmarks and the relatively short run time, I'd have to think that runtime optimizations really atrribute to much (if anything).

      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.

      No. Runtime optimization is no substitute for a profiler. A profiler works at a higher level. It will point out which code you will have to re-write or re-structure. No runtime optimizer can do that without incurring unacceptable overhead. Sure there is some overlap, but it's not much.

      Which means, all it was that made these benchmarks in Java faster is JIT, right?

      Yet you say: 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

      What point are you actually trying to prove here? That C++ has got to be faster because it is all compiled to machine code to begin with? Or that the JVM has got to be slower because it has to include this extra step?

      I think this runtime optimization is fascinating, and I can see how it may help for relatively large/long running applications. But you got to realize that it has to come at an overhead. The more runtime optimization, the more overhead of the optimizer.

      Again, JIT has got to have overhead, so by definition it's slower than pre-compiled code.

      I think there's a lot of mis-conception and fanboyism going on here.

      Here's a little summary of all the relevant stuff:
      a) Java & C++ are languages. They don't have 'speed' by nature. One isn't faster than the other. In fact Java and C++ are so similar that they are almost interchangable.
      b) Implementations of benchmarks that are using different languages need to be written as similar as possible AND be written by experts in the respective language.
      c) g++ doesn't generate the fastest code, especially if you don't turn on all optimizations.
      d) measuring the speed of your runtime libraries is fun, but doesn't say anything about how fast your programs _can_ be written in a certain language.
      d) JIT is NOT a speed advantage of Java over C++. It's a portability advantage.
      e) runtime optimizations could potentially have an advantage but I'd like to see concrete proof of that.

    6. Re:Optimization at runtime vs. compile time by cardshark2001 · · Score: 1
      Let's turn the languages around. Suppose we write a VM in Java, which runs byte code compiled from C++ programs. Then it can profile the running C++ byte code and optimize the critical sections. A C++ compiler that translates directly to machine code cannot do that.

      Maybe the compiler can't, but the developer could write code that would do as well or better than any sort of JVM specific optimization you can name. The JVM is not going to outperform John Karmack by doing run-time profiling. If you think Doom 3 could be written in Java, you're kidding yourself. Seriously, do you think a run-time profiling algorithm can do better than a proficient human with a profiling tool?

      --
      WWJD? JWRTFA!
    7. Re:Optimization at runtime vs. compile time by Anonymous Coward · · Score: 0

      oops: profile guided optimization works for compiled languages too :)


      microsoft visual c++ 2005
      intel c++ 8.0
      intel fortran 8.0

    8. Re:Optimization at runtime vs. compile time by Trinition · · Score: 1

      Seriously, do you think a run-time profiling algorithm can do better than a proficient human with a profiling tool?

      Ok, Mr. Proficient Human With Profiling Tool, quickly state how you'll optimize your program for each and every input it will ever see so that those optimizations will be coded intop the program.

      You see, runtime profiling has the ability to examine the state of the program as its running and respond to changing conditions with chaning optimizations.

      Now, perhaps you mean a C++ programmer could write code into his program that monitors various values in the program and then starts swapping function pointers around to use function implementations that are more optimal for the state. If that is your point, then go have fun with that!

    9. Re:Optimization at runtime vs. compile time by cardshark2001 · · Score: 1
      You see, runtime profiling has the ability to examine the state of the program as its running and respond to changing conditions with chaning optimizations.

      I know what it is. Your claim that it is faster to profile and recompile in runtime rather than to write well-optimized native code is what I think is rather funny. If it really was faster, Carmack would write D3 in Java.

      No, it's a trick to make non-native code run faster. That's all it is. Does it make java faster than it otherwise would? Yes (but only sometimes - do I need to explain to you the cases where it would actually make the code slower?). Does it make Java faster than hand-optimized c++? Not by a damn sight.

      You ask me how a c++ programmer could optimize a program for every possible input.

      First of all, Java doesn't do that. If it did, it would eat all your available memory very quickly. In some situations, it might find a loop invariant and optimize the code accordingly. Every loop doesn't necessarily even have an invariant that your magical java profiler can optimize away.

      Secondly, what you are talking about is a very general approach to optimization. What I am talking about is knowing your architecture and tweaking your code to run as fast as possible on a given CPU. You just can't do that with Java, you have to hope that your JVM does it for you. Can you guarantee that you won't get a pipeline stall because your runtime optimizer is so bad ass? Do you even know what a pipeline stall is? Can you make sure that your critical code fits into the cpu cache? Can you be sure that the JVM will do it for you?

      Can you write native code in java for the times when your compiler does the wrong thing (aka assembly code)? You can with just about every c++ compiler (even gnu!), but you can't do it with Java, period.

      Son, I don't have time to educate you. If you really want to learn, instead of running your mouth off here on slashdot, pick up a book on the Intel hardware (or your favorite cpu), and play around with it.

      --
      WWJD? JWRTFA!
    10. Re:Optimization at runtime vs. compile time by Trinition · · Score: 1

      Pick up a book? I was programming in x86 assembler when I was in diapers! Well, not diapers, but I coudln't drive yet.

      As I've said before, you *can* do assembler for the JVM -- you just don't use a Java compiler, you use a compiler made for compiling Java assembler instructions into Java bytecodes.

      And as for the HotSpot optimizing for every known input, it doesn't do that all at once. It attempts to optimize on the fly. And it's not just for invariants. It can do so as values change. It may decide to unroll a loop when the counter is less than 3 but keep it in a loop when its more than three. And it might decide to change that critical point on the fly.

      I'll give you that it *is* general optimization. I think it has less to do with optimizing for the hardware but optimizing for how your program is expected to operate. As others have pointed out, CPUs already mangle the instructions so much internally, that you're compiler itself doesn't even write the actual instructions that will be exeucted anymore.

    11. Re:Optimization at runtime vs. compile time by Anonymous Coward · · Score: 0

      My JVM can know my CPU's cache size and how to schedule instructions for its pipelines. You can't because CPU models vary dramatically and you don't know which one I'm using.

  208. Benchmarks... by abertoll · · Score: 2, Insightful

    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.

    --
    "he drew his sword Ringil that glittered like ice... and he wounded Morgoth with seven wounds..."
    1. Re:Benchmarks... by mlk · · Score: 1

      This is mostly true.
      However, some language put extra requirements on the Runtimes. In Java case this is a GC. The GC, while is a great extra for most developers, for speed it can be a pain in the arse, and kick in during your game loop, slowing down the game.

      --
      Wow, I should not post when knackered.
  209. Re:That's what happens with the lowest common GUI by Anonymous Coward · · Score: 0
  210. The Azureus BitTorrent client by Opiuman · · Score: 1

    Azureus is a good example of the only Java application that I use regularly (aside from Eclipse). And it is also based on SWT. I don't care what the acronym is supposed to stand for, I say SWT is short for 'sweeeeet'.

  211. Function calls by BenjyD · · Score: 4, Interesting

    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.

    1. Re:Function calls by Xugumad · · Score: 1

      In particular, having proven that method calls, as implemented by G++, are significantly more expensive, obviously a recursive implementation is going to be much slower...

    2. Re:Function calls by BenjyD · · Score: 1

      Interestingly, compiling the recursive example with -fomit-frame-pointer improves performance by ~25% (2.7s vs 3.7s)

    3. Re:Function calls by Xugumad · · Score: 1

      For anyone that wants to try that test themselves, here's a quickly thrown-together for-loop version of the fibo.cpp benchmark.

      // -*- mode: c++ -*-
      // $Id: fibo.g++,v 1.3 2001/06/20 03:20:02 doug Exp $
      // http://www.bagley.org/~doug/shootout/

      #include <iostream>
      #include <stdlib.h>

      using namespace std;

      unsigned long fib(unsigned long n) {
      unsigned long *buffer;
      unsigned long i;
      unsigned long value;

      if (n < 2) return (1);

      buffer = (unsigned long *)malloc (sizeof (unsigned long) * (n + 1));

      buffer[0] = 1;
      buffer[1] = 1;
      for (i = 2; i <= n; i++) {
      buffer[i] = buffer[i - 1] + buffer[i - 2];
      }
      value = buffer[n];

      free (buffer);

      return(value);
      }

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

      cout << fib(n) << endl;
      return(0);
      }
    4. Re:Function calls by Anonymous Coward · · Score: 0

      Why even bother with that? Just solve the linear difference equation and calculate the damn result with the FPU.

    5. Re:Function calls by Anonymous Coward · · Score: 0

      You mean something like:

      double phi = (1 + sqrt(2))/2; /* the golden ratio */

      int
      fib(int n) { /* you can use more accurate numbers here, but these work up to 64 bit */
      return (n < 2) ? 1 : (int) (pow(phi, n) * 2584 / 3571);
      }

  212. Re:Can I have an infinite budget to write the code by sysopd · · Score: 1, Insightful
    I wish all Unix GUIs were done in Java.

    That line made my blood curdle. Of all the UNIX apps I've used, the ones that were written in Java are my least favorite and least used apps. I prefer apps written in C with a toolkit like Qt or Gtk+. Both of those are exceptionally fast and modern looking. Toolkits like WxWindows compile natively with no extra dynamic libraries required and are crossplatform.

    But as anyone really using *NIX knows (yes I'm talking about you gentoo, sourcemage, LFS and slackware guys), you always pick the app written in C before the app linked against libstdc++. It may sound elitist but it just seems that people writing in C know what they're doing and take the time to write more solid code. Not to say you can't write a crapwagon C program, perhaps its just easier to fuck it up when you're writing C++.

    To go back to your line that made me choke, "I wish all Unix GUIs were done in Java." Perhaps large one-off or custom design software could benefit from Java. But I think this is the minority not the rule. The apps I use on a daily basis are the window manager, xterms, media players, web browsers, document viewing/creation apps, etc. These types of apps have matured over the last 10 years and are all (the ones I use at least) written in C. That is why I can use X and actually do work with no problems on my P133 laptop. Compare that to OpenOffice, Limewire, etc al that I would not touch with a 10' pole for fear of my laptop shutting itself quickly and breaking off my fingers in retaliation.

  213. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    Well duh. He didn't run it on Gentoo.

  214. Study Proves Sun Java Compiler Faster than GCC by xp · · Score: 4, Insightful

    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

  215. C bigotry by serviscope_minor · · Score: 1

    If you want speed, for God's sake, write it in C! Oh, another C vs C++ bigot. C, being largely a subset of C++ with a few minor syntactic exceptions is not going to be faster than C++ since you could just write a C program anyway. Now that that is out of the way, C++ allows you to write fast code more easily, by providing templates. Sure, templates have some warts (thought I have no idea what you're talking about code being "unwoven", desplite having done planty of template programming), but it's generally easier than doing the equivalent with macros. Yes, it is possible to write slow code in C++, maybe it is easier than in C, if you have not much clue as to what you are doing, but it is precisely as easy to write fast code in C++ as it is in C, since C++ is a superset of C.

    --
    SJW n. One who posts facts.
    1. Re:C bigotry by Antique+Geekmeister · · Score: 1

      You wrote: "but it is precisely as easy to write fast code in C++ as it is in C, since C++ is a superset of C." Unfortunately, the need for dealing with templates and the various overhead insanity of both C++ and Java is a source of often incredibly badly under-optimized and painful code. Neither C++ nor Java are good toolkits for writing fast code. The code may be more portable, and given the additional structures of things like "Object Oriented" code may be more suitable to a large project. But for speed? No.

  216. Benchmarks? by slapout · · Score: 2, Informative

    It's not the benchmark's that count. It's the programs I need to run. Every program I've tried that's written in Java takes longer to start up than one written in C/C++. Althought that may change with .Net :-)

    Java has gotten better though. The programs are usable now days. (Just have that start up time as the virtual machine loads.) Use to be the programs loaded slow and ran slow.

    --
    Coder's Stone: The programming language quick ref for iPad
    1. Re:Benchmarks? by Anonymous Coward · · Score: 0

      give me a break. I've done extensive tests comparing .NET 1.1 and jdk1.4.2 and my own tests show jdk1.4.2 is 15-30% faster on real server applications. For multi-threaded server applications, Java is able to scale considerably better. since Microsoft's EULA prevents me from posting results, I can't disprove shit. I wouldn't want to post results anonymously, since that would be cowardly. On the otherhand dispelling FUD doesn't require a name :)

  217. Re:Caught up with the speed, but still the ugliest by Christopher+Cashell · · Score: 2, Insightful

    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?

    --
    Topher
  218. Re:Can I have an infinite budget to write the code by sysopd · · Score: 1
    Qt for X11 is free. The other OS/Arch options are the ones that are not free:

    Qt/X11 Free Edition

  219. More info, after some testing by Cthefuture · · Score: 4, Insightful

    I just went through and tested the hash2 benchmark and found that I was correct. The C++ version slaughters the Java version (even in "server" mode). This is completely different than what this dude's page shows.

    Here is the "correct" code for hash2.cpp:

    #include <stdio.h>
    #include <iostream>
    #include <ext/hash_map>

    using namespace std;
    using namespace __gnu_cxx;

    struct eqstr {
    bool operator()(const char* s1, const char* s2) const {
    return strcmp(s1, s2) == 0;
    }
    };

    struct hashme
    {
    size_t operator()(const char* s) const
    {
    size_t i;
    for (i = 0; *s; s++)
    i = 31 * i + *s;
    return i;
    }
    };

    int
    main(int argc, char *argv[]) {
    int n = ((argc == 2) ? atoi(argv[1]) : 1);
    char buf[16];
    typedef hash_map<const char*, int, hashme, eqstr> HM;
    HM hash1, hash2;

    for (int i=0; i<10000; i++) {
    sprintf(buf, "foo_%d", i);
    hash1[strdup(buf)] = i;
    }
    for (int i=0; i<n; i++) {
    for (HM::iterator k = hash1.begin(); k != hash1.end(); ++k) {
    hash2[(*k).first] += k->second;
    }
    }
    cout << hash1["foo_1"] << " " << hash1["foo_9999"] << " "
    << hash2["foo_1"] << " " << hash2["foo_9999"] << endl;
    }

    --
    The ratio of people to cake is too big
    1. Re:More info, after some testing by GooberToo · · Score: 2, Interesting

      I have not looked at the changed code, but I do reproduce your results:

      java-server: 14.93user 0.10system 0:15.67elapsed 95%CPU
      g++-O2: 8.10user 0.03system 0:08.38elapsed 96%CPU

      That places g++ about twice as fast as java, at that benchmark, assuming the code is correct. ;)

    2. Re:More info, after some testing by Cthefuture · · Score: 1

      You can also replace the strcmp with a string equals function and get even more speed. strcmp checks the string ordering which you don't need for the hasher.

      So change the eqstr class to the following:

      struct eqstr {
      bool operator()(const char* s1, const char* s2) const
      {
      unsigned int i;

      if (!s1 || !s2) return 0;

      for (i = 0; s1[i] != 0; i++)
      { if (s1[i] != s2[i]) return 0; }

      if (s1[i] == s2[i]) return 1;
      else return 0;
      }
      };

      (reformated a bit to get past Slashdot's insane "whitespace" nonsense)

      --
      The ratio of people to cake is too big
    3. Re:More info, after some testing by GooberToo · · Score: 1

      Keeping in mind, I'm not a java guy, but I did see something that I want to question. Above, you have "hashme", which is clearly about as simplistic as simplistic can get. I do not see the equivelent in the java code. So, I'm assuming that means it's using some other hash method which is built in. Is the built in hash method comparable to your very simplistic hash method? If not, you're benchmarking an apples and orages difference.

      Aside from that concern, everthing else looks good. Care to address my concern?

    4. Re:More info, after some testing by Cthefuture · · Score: 1

      True, and when not using the "hashme" thing it uses some default version in whatever implementation of STL you are using. Are any of these comparable to the builtin Java version? I don't know.

      I think the big thing (for me) is that at least in C++ I have a choice. I can swap these functions out, use the default version, or whatever I want. That's not so easy with Java (if you want maximum performance at least).

      --
      The ratio of people to cake is too big
    5. Re:More info, after some testing by GooberToo · · Score: 1

      I can't argue with that. As is, it certainly makes sense to have a hash as lightweight as is required. In this case, it appears that your implementation fits the bill nicely. Just the same, I'm hoping that some Java guy will jump in and offer some insight so that we could perhaps run a true apples to apples comparison.

      Personally, I'm content to accept your implementation as valid as long as people are aware of the caveat.

      Good work btw. ;)

    6. Re:More info, after some testing by Anonymous Coward · · Score: 0

      you can override the Object.hashCode() function in any Object you create, though String is a final class. here's the standard hash function for String. it looks like the same functionality as yours

    7. Re:More info, after some testing by Trinition · · Score: 1

      Java's implementation of hashCode() for String could vary, as I understand it, by language implementor (i.e. Sun vs. IBM). Regardless, I looked in Sun's JDK 1.4.2 source code. Here's the basic algorithm:

      1. If the stored hashcode is not zero, return it
      2. get local vairable copies of the member variables (I'm assuming these are trivial stack allocations)
      3. Looping index from 0 to length, do...
      4. hashcode = 31*hashcode + character at index
      5. Store hashcode
      6. return hashcode

      As I read it, steps 3 and 4 are the meat of this algorithm, and looks equivalent to the C++ version the grandparent post had. I'm nore sure how much the checking/storage of the hashcode would impact things -- unless your hashcode happened to be the unlucky zero in which case you'd be screwed! But to have 0 hashcode, you're string would have to be empty (in which case the loop would terminate quickly) or every character would have to be '\0' which is probably not likely.

    8. Re:More info, after some testing by toga98 · · Score: 1

      I ran the parent's code against the java code (minus an unecessary cast and object allocation) with an argument of 12345.

      java -server: 54 secs
      cpp: 47 secs

      I'm certain you could tweak the java code quite a bit and the cpp code too and get both of those numbers down even further.

    9. Re:More info, after some testing by Malvolio · · Score: 1

      You should first check if s1 and s2 are the same pointer. Also, use true and false when dealing with bools, and use size_t for indexing strings. Here's a somewhat terser variant that uses pointer arithmetic instead of indexes:

      struct eqstr {
      bool operator()(const char* s1, const char* s2) const
      {
      if (s1 == s2) return true;
      if (!s1 || !s2) return false;

      while (*s1 != '\0' && *s1 == *s2)
      s1++, s2++;

      return *s1 == *s2;
      }
      };

    10. Re:More info, after some testing by Cthefuture · · Score: 1

      Yeah, thanks. That code was copied from some older C hash code I had (the reason for the non-bool items).

      --
      The ratio of people to cake is too big
    11. Re:More info, after some testing by GooberToo · · Score: 1

      Wow. Fair enough. That squarely places the java implementation, assuming the c++ version were to be completely optimized, more than half the performance.

      I think that one has been completely debunked.

      Thanks.

    12. Re:More info, after some testing by GooberToo · · Score: 1

      Please share your updated java code.

    13. Re:More info, after some testing by Trinition · · Score: 1

      Debunked? I don't know. Certainly shows that with hand-tuning, C++ can be faster. BUt again, as I brought up in another post in this topic, what is C++? Is it the language? Is it the "standard" libraries? I mean, what the benchmark showed for String hashign is that Java is faster. But that seems to only be because the standard hash routine chosen (and forgive me if it was standard and correct me) for C++ is slow. But if one were to write C++ programs, should they expect to have to start throwing out parts of the standar dlibraries in favor of alternativees because the standard sucks so bad? I suppose one could throw out Java's implementation for one linked through JNI to an ASM-implemented String hashing routine. Or what if Java standard were updated to include a VM instruction for hashing Strings so that that instruction could be optimized in the VMs dpeloyed to various platforms?

      The benchmark is junk because the benchmarkere didn't systematically state -- or even understand -- hwta it is they were testing. In most if not all case, it was apples ot oranges.

    14. Re:More info, after some testing by Anonymous Coward · · Score: 0
      Here is the "correct" code for hash2.cpp:

      #include <stdio.h>
      #include <iostream>
      #include <ext/hash_map>

      What are you trying to measure? Which language is better or which library is better?

      If you are trying to benchmark the languages, use equivalent code. Using the libraries you suggest would only be fair if the library was implemented in both languages. Otherwise you are measuring several things in just one test.

      C++ is stil faster than Java for matrix multiplication, but then FORTRAN is way faster than C for matrix multiplication. It only proves than whenever Java is too slow, it should call FORTRAN, or even faster, call ML.

  220. Right tool for the job by willCode4Beer.com · · Score: 1

    I started writing assembly in the early eighties as a kid. At the time, it was the right tool for the job. RAM and storage were a premium.

    Today, I code in Java and C++. Why, productivity. I've found Java to be one of the most productive languages I've seen (C# may have caught up).

    If I were writing code for micro-controllers, then I'd still be writing assembly because it would be appropriate. Writing complex business applications deployed on large clusters of servers would be insane to do in assembly.

    To give you credit. I do notice that developers with a strong assembly background write much better Java and C++. Perhaps because they understand what the machine is doing. They know how to use javap to disassemble class files to see what the compiler is creating.

    To take credit away. Most projects need the balance of speed and speed of develpment. Usually this is a trade-off between C (speed) to Java (rapid dev). The article suggests that the speed sacrifices are much less than they used to be.

    --
    ----- If communism is a system where the government owns business, what do you call a system where business owns govern
  221. Re:java methcall benchmark not making virtual call by bgs4 · · Score: 1
    If the class were created on the stack (as any C++ programmer would create it in this case) then there is no reason the compiler couldn't inline the call.

    The point is that this test was obviously created to exploit the fact that java uses jits. This would be ok if there were a test specifically designed to exploit every little advantage C++ has over java, but there doesn't seem to be.

  222. Java Faster Than C++? by Dun+Malg · · Score: 2, 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)

    --
    If a job's not worth doing, it's not worth doing right.
    1. Re:Java Faster Than C++? by khuber · · Score: 1

      I wanted to see the "of course Java is slower, it's interpreted!" argument one more time.

    2. Re:Java Faster Than C++? by Dun+Malg · · Score: 1
      I wanted to see the "of course Java is slower, it's interpreted!" argument one more time.

      Pffff! That's exactly the sort of nonsense I'd expect from a vi user!

      heh

      --
      If a job's not worth doing, it's not worth doing right.
  223. What about a contest? by TSTM · · Score: 1

    There seems to be very much bragging on both sides - "You could have used optimizer x, written better code, etc".

    It seems that to get accurate results which language is actually faster, we should start a contest where programmers can defend their favourite language as much as they want, and do all the optimizing they can possibly squeeze out of the language.

    There could be just some different problems to solve or things to do with the program, and the thing should be done exactly the way as described by the contest starter.

    After a while, when all the contestants have submitted their code, and it has been tested by the contest jury, we would have a quite clear winner, at least for the few problems presented in the contest?

    So, all we need now is someone willing to get some reputation from arranging a contest like that. =)

  224. String concat sillyness by danharan · · Score: 4, Informative
    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.
    --
    Information: "I want to be anthropomorphized"
    1. Re:String concat sillyness by khuber · · Score: 1
      public class Strcat3 {
      public static void main(String args[])
      {
      long start, elapsed;
      start = System.currentTimeMillis();

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

      char[] chars = "hello\n".toCharArray();

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

      System.out.println(str.length());
      elapsed = System.currentTimeMillis() - start;
      System.out.println("Elapsed time: "+elapsed);
      }
      }
    2. Re:String concat sillyness by CoreyG · · Score: 1

      Don't forget that java.util.StringBuffer is thread-safe (synchronized).

    3. Re:String concat sillyness by danharan · · Score: 1
      Interesting... that is indeed faster. Thanks for the tip!

      I thought the following was equivalent to what you were proposing:
      for (int i=0; i<n; i++)
      {
      str.append("hello\n".toCharArray());
      }
      But it's actually much slower than any solution except the original, whereas your solution -declaring a char[], then appending it- is some 20 milliseconds faster than simply appending the String. I thought it exceedingly weird, so I took a look at the source code for some of the classes involved.
      public synchronized StringBuffer append(String str) {
      if (str == null) {
      str = String.valueOf(str);
      }

      int len = str.length();
      int newcount = count + len;
      if (newcount > value.length)
      expandCapacity(newcount);
      str.getChars(0, len, value, count);
      count = newcount;
      return this;
      }

      public synchronized StringBuffer append(char str[]) {
      int len = str.length;
      int newcount = count + len;
      if (newcount > value.length)
      expandCapacity(newcount);
      System.arraycopy(str, 0, value, count, len);
      count = newcount;
      return this;
      }
      It's no wonder that appending a char[] is faster! Checking to see if a String is null (and re-casting as object and then appending "null" if it is) obviously slows things down. This may not be a surprise to you, but it was to me... and quite relevant since I have code that makes heavy use of StringBuffers in long loops, so this will come in handy.

      I guess I need to read source code more often :)
      --
      Information: "I want to be anthropomorphized"
  225. Where is "I Hate Java" Nathan "ncm" Myers? by nick_urbanik · · Score: 1
    It's sad that Advogato is down, because I could link to the wonderful Anti-Java, pro C++ flame wars started by Nathan, C++ library contributor and initiator of the I Hate Java group on Orkut.com. But I don't have access yet. Come on Nathan, this news item on Slashdot gives you just the right soapbox to stand on!

    It must be a wonderful discussion, because as pointed out by Nathan himself: It's a safe place to rant without being contradicted by apologists, toadies, people worried about their unwise career choices, or even facts.

  226. Re:That's what happens with the lowest common GUI by Anonymous Coward · · Score: 0

    Okay, Swing is the SECOND ugliest widget toolkit.

  227. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    Well that depends on if you wrote the error messages. I could barely make it through your post, what with the extra characters and all.

  228. Re:This doesn't make any sense... by BillyBlaze · · Score: 1

    But then you don't get the cross-platform goodness of having only one binary to distribute. (Although most Java apps I've seen don't have that much anyway.)

  229. -O3? by Kupek · · Score: 1

    Why stop at -O2 and not use -O3 for g++?

    1. Re:-O3? by BenjyD · · Score: 3, Informative

      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)

    2. Re:-O3? by Kupek · · Score: 1
      I should have RTFA. My fault. His reasoning was "On the other hand, -O3 performs space-speed tradeoffs," however, the man page for g++ that I've always read says:
      -O3 Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the -finline-functions and -frename-registers options.
      From what I know, the STL performs better if you inline - it basically gets rid of a lof the wrapper classes. And on the method call comparison - the one where Java was faster by an order of magnitude - g++'s optimizer might be smart enough to inline that call.
    3. Re:-O3? by Kupek · · Score: 1

      In these cases, no inlining is taking place, or it makes no difference.

      The metchall.cpp is one I was wondering about. Now that I think about it, it makes sense that no inlining is happening; you're calling a virtual member function through a pointer. You have to go through the virtual function table at run time, the compiler can't know ahead of time what to inline.

      Inlining isn't going to help fib.cpp - you can't inline a recursive function. For the matrix.cpp case, the function call overhead is nothing compared to the aglorithm it's running. Something you can do with C++ that you can't do with Java is hand optimize the matrix multiplication to avoid cache misses. That can speed it up by orders of magnitude. To my knowledge, you can't do that in Java. The (small) speed up you saw when you told it what processor you're using might have to do with keeping stuff in the L1 cache, or even on the registers.

    4. Re:-O3? by dtfinch · · Score: 1

      How about -O3 -fomit-frame-pointer -funroll-loops? Those two extra optimizations are pretty important, but disabled even with -O3 because they hinder debugging, which is not a concern when producing a release build.

    5. Re:-O3? by BenjyD · · Score: 1

      I tried -fomit-frame-pointer with several of the benchmarks and for many it improved performance by about 25% (matrix,fibonacci, methcall, ackermann).

    6. Re:-O3? by Anonymous Coward · · Score: 0

      matrix.cpp -O2 1.8s -O3 1.8s (interestingly, adding -march=athlon-xp for my machine reduces time to 1.5s)

      What's so interesting about two decades newer cpu having more room for optimization than i386?

  230. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    Most users use 1 platform, and expect an app to look like and behave consistently with other apps on that platform.

  231. Re:Can I have an infinite budget to write the code by mstorer3772 · · Score: 1

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

    Sorry but when you use 4 engineers for 6 months you can't claim no to little effort.
    "

    He didn't say "no to little effort". He said NO WAY with AS LITTLE effort. The original poster believes that it took less time because of his choice of language.

    I'd say it was the proper design up front, but that's me. I'd guess that the original imaging app was a hack, held together with chewing gum and bailing wire by their description. The new app has an actual design.

    Language choice? Pretty much a wash. It boils down more to APIs than keywords, in my experience. He who has the easiest architechture wins the "ease of implementation" award, regardless of how you define a loop or how you terminate a line.

    --
    Fooz Meister
  232. who cares by Xiaus · · Score: 1

    even if java is a few seconds faster, it doesn't matter, its the same concept of "our computer is 2 seconds faster, pay us an extra 100$ and be faster by 2 seconds", only, learn our language, and be faster. A lot of it is the methods used, and even if you used the fastest method for whatever your doing, it doesn't matter if it is faster by a few seconds. I dont think any of us should choose what programming language we use by speed tests, its what the programmer feels most comfortable using.

    1. Re:who cares by thepr0fess0r · · Score: 1

      I disagree... if I'm not yet "comfortable" with java (or C, or ML or whatever) but I can write what I'm doing to be twice as fast in half the code, I should sure as hell get comfy real fast. To say "xyz is a couple 'seconds' faster doesn't matter" depends on the context. If I'm doing an 8 hour render, a couple seconds is nothing, but if I'm waiting for google to load, a couple seconds is an eternity.

  233. Re:Caught up with the speed, but still the ugliest by Sivar · · Score: 3, Interesting
    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++.
    --
    Computer Science is no more about computers than astronomy is about telescopes. --E. W. Dijkstra
  234. I don't know about Java, but... by callipygian-showsyst · · Score: 1, Troll
    I refuse to run Java for political reasons (I don't care to support pedophilia), but I recently starting doing a lot of work in Microsoft's C#, which is similar in it's implementation.

    Like Java, C# is compiled to an intermediate code for a "virtual machine" that is typically JIT compiled for the target processor. I've been amazed at the speed. I'm doing graphics applications where I'm moving bits around manually, and C# is plenty fast! And it's nice to have garbage collection and modern features.

    C# also has some other advantages over Java: it's a standard language (it has been submitted to the ECMA standardization committee), and has advanced features like "generic types" (similar to templates), pointers, and good XML serialization support.

  235. Re:Some performance myths by shadow_slicer · · Score: 1

    Don't forget that binary x86 instructions are also bytecodes. This means that you could get the benefits of dynamic recompilation by running an X86VM on your x86 machine and could program in any language you want. In fact modern x86 processors already do something like this in hardware as they translate opcodes into micro-ops.

    Though it does seem rather odd for the "future" of programming to be writing code to feed to an optimizor/translator which feeds code to an optimized translator which feeds code to the real processor.

  236. Java IS faster then C++ by Anonymous Coward · · Score: 0

    in some tests. And C++ is faster in others. So what? If you select development platform solely on speed, you're making a big mistake.

  237. Could C++ compile to Java bytecode? by NoMercy · · Score: 1

    This would be an interesting one wouln't it...

    1. Re:Could C++ compile to Java bytecode? by gatkinso · · Score: 1

      Can you say .NET......? :-)

      --
      I am very small, utmostly microscopic.
  238. Re:This doesn't make any sense... by Anonymous Coward · · Score: 0

    Isn't this more or less the point of GCJ?

  239. GCC 3.4 Significantly Faster. by Anonymous Coward · · Score: 0

    GCC 3.4 has a new parser, no longer based on yacc.

    GCC 3.4, also has a new framework for optimization -- gimple and generic.

    He is running, technically, and outdated toolchain. A new test should be performed with glibc compiled with GCC 3.4, and GCC 3.4.

    gcc.gnu.org

    1. Re:GCC 3.4 Significantly Faster. by AlastairMurray · · Score: 0
      GCC 3.4 has a new parser, no longer based on yacc.
      Won't make the binaries any faster.
      GCC 3.4, also has a new framework for optimization -- gimple and generic.
      Umm... no it doesn't. They're both in GCC 3.5, which isn't even close to being stable. x86 binary performance only improved marginally in 3.4 over 3.3. (some other arches, notable x86-64 saw much more significant improvements). Sorry, don't mean to be bitchy, it's late in my neck of the woods.
    2. Re:GCC 3.4 Significantly Faster. by cimetmc · · Score: 1

      GCC has some improvements and may produce a bit faster code, thought not that significantly better. The new tree-saa framework will only be available in the next version of GCC.
      Still, there are a number improvements to libstdc++ in GCC 3.4 and this could actually make a difference in some of the benchmarks.

  240. Re:Can I have an infinite budget to write the code by LDoggg_ · · Score: 1

    He said the original program took 12 man years, and the new one took 2 man years and is a much better application.
    Definetly little effort relatively speaking.

    --

    "If they have both, tell them we use Linux. And if they have that, tell them the computers are down." -Dave Chapelle
  241. Re:Caught up with the speed, but still the ugliest by aled · · Score: 1

    Why not? Give a reason.
    BTW templates error messages stink, at least in GCC and Visual C++.

    --

    "I think this line is mostly filler"
  242. Abrash's Zen has an explanation by Anonymous Coward · · Score: 0

    Of course I didn't RTFA, but as long as it's apples-to-apples it shouldn't be a problem.

    Check out Michael Abrash's Zen of [Assembly|Graphics], one of those... It has a chapter on optimization involving recursive versus non-recursive functions. He implements, IIRC, a BSP-traversal algo both recursively and non-recursively, and shows that without optimizations they are quite different, but when fully optimized (in the compiler) their performance is nearly identical.

  243. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    Those are likely coming from his Linux box.

    Windows does not enable smart quotes for edit boxes, except when they are pasted directly into the box. There is no automatic handling of quotes in Windows controls, unlike Linux which tries to outthink the user at every step.

  244. Re:Caught up with the speed, but still the ugliest by saden1 · · Score: 1

    What if I were to tell you I use mozilla? You would have looked a lot smarter if you had told me to "select HTML Formatted" before making a post or even preview your post before pressing the submit button.

    --

    -----
    One is born into aristocracy, but mediocrity can only be achieved through hard work.
  245. Timing strategies by Adruab · · Score: 3, Interesting

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

  246. Obligatory Bash Quote... by MP3Chuck · · Score: 3, Funny

    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

    1. Re:Obligatory Bash Quote... by MP3Chuck · · Score: 1

      Or, in proper format:

      #338364 +(1308)- [X]
      [Alanna] 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

  247. Re:Thanks. Article is a troll. by Anonymous Coward · · Score: 0
    Moderators: Please note that "twitter" is a known fanatical psycophant whose obnoxious offtopic rants are legend here on Slashdot. It doesn't matter what the topic is, he'll find a way to scrape in some pointless Microsoft bashing. While nobody expects us to love Microsoft in any way, his particularly tepid style of calling anyone he replies to "troll" or "liar" or "fanboy" because he happens to disagree with whatever they're saying is well documented and should not be rewarded. If anything, twitter is the type of person that should not be part of the open source/free software community. He is an anathema to all that is good about free software.

    I'm posting this so that you (the moderator) have some context to consider twitter and not mod him up whenever he posts his filler preformatted rants about installing Knoppix or whatever that unfortunately get him karma every single time and allow him to continue posting his trademark toxic crap (read on) day in and day out. You may consider this a troll - I consider it community service. And I ain't kidding.

    If you're a /. subscriber, I invite you to look through some of his posting history. I guarantee that you'll be hard pressed to find someone that is more "out there" than twitter. You'll also probably notice he's got quite an AC following. Don't just read his posts, make sure you go through the replies.

    To get an idea of what I'm talking about, check this post out. I mean, this is an article about email disclaimers, right? The parent of the post is complaining about the ads in the linked page and so on, and twitter actually goes off on a rant to blame it on Microsoft and recommend Lynx. WTF?

    Here's another. In this post twitter not only calls the OP a troll but attempts to "tell it like it is" while making some vague argument about "GNU". Yes, if you're confused, you're not alone. The reply (modded +4) proceeds to simply destroy his bogus argument. You will notice he did not reply. This is what some people call "drive-by advocacy". A sort of I'll just leave you with my thoughts here and move on to the next flamebait kind of deal. In fact, he almost never replies because he knows that his fanatical arguments simply do not hold up to any sort of discussion. It's not that he's chosen the wrong cause - he's just going at it in a completely wrong way.

    More? Just read though this post and the subsequent replies. I guess this stands on its own.

    More? Bad spelling in astounding conspiracy theories, more offtopic FUD and uninformed "I'm right, look at me" rants, promptly proven wrong. Worse even, twitter wants to be RMS, apparently (that first one is a winner). I mean, really. You think?

    FUD, FUD, FUD, FUD, offtopic FUD

  248. Command and source/test review. by Ninja+Programmer · · Score: 4, Informative

    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.

    1. Re:Command and source/test review. by arkanes · · Score: 4, Informative
      The method call is a really egregious case of bad methodolgy. The C++ test he's using was designed to test method call overhead, which is why it returns by value instead of refrence. The massive performance improvement from the JVM (server only, note) is the JVM aggresively inlining the call (and it's a single method call in a tight loop, an obvious inline candidate), so what he's measuring is just loop performance, not method call overhead. If he hadn't disabled loop unrolling and function inlining in GCC (via O2), C++ would have performed much better.

      It's worth pointing out that inlining is a case where a VM can really shine for optimizing because it has alot more options available (partial inlining, etc) and can make better decisions about tradeoffs. But this particular benchmark is comparing apples to oranges.

    2. Re:Command and source/test review. by norton_I · · Score: 4, Informative

      The method test is limited by two things: First, gcc appears unable to inline virtual method calls through a pointer to an object, even when the exact type is available, second, he didn't turn on loop unrolling. Loop unrolling is a huge, huge advantage on any sort of null benchmark like this.

      Changing the objects the be stack allocated and adding -funroll-loops moves the c++ benchmark up to just ahead of the java benchmarks.

      Of course, this does point to several advantages of a runtime optimizer. A static optimizer will never be as good at optimizing virtual function calls as a runtime optimizer, since it will never be as good at identifying types. Also, a runtime optimizer will always be better at creating specializations of existing functions (creating a special version of a routine when some input value is treated as a constant).

    3. Re:Command and source/test review. by jmccay · · Score: 1
      One part of the notes I find interesting is this:

      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. I compiled the C++ code with:

      g++ [test].cpp -O2 -march=i386 -o [test]-386

      g++ [test].cpp -O2 -march=i686 -o [test]-686


      This brings me to ask the question: what exactly does the C++ results represent? Does it represent the best value, average, or slowest of the results with the two target platforms?
      Then, there is the machine on which it was compiled. A P4? Let's see the results on a P3 or P2.
      This test doesn't reflect C++ strengths--such as the STL and generic programming. I question these results. I still find it hard to believe that an interpreted language runs faster than a compiled language, and before all you Java zealots reply, on most systems, if not all, it doesn't run with out the aid of the jvm--therefore it is an interpreted language.
      --
      At the next eco-hypocrisy-meeting, count the private jets used to get to the meeting. Should be interesting to see that
    4. Re:Command and source/test review. by Anonymous Coward · · Score: 0

      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 OP was talking about run-time optimizations, in which case this is pretty much just memoization (which is basically fancy function-result-cacheing).

    5. Re:Command and source/test review. by alex_kotov · · Score: 1

      Actually if you will look into hash*.cpp C++ sources you'll see that they were constructed to be as buggy and slow as possible (unnecessary strdup() with corresponding memory leaks, char* instead of std::string which should be more logical for C++ code, hashl[ (*k).first ] instead of k->second and so on).

    6. Re:Command and source/test review. by Inoen · · Score: 1
      Since the function called is virtual, there isn't much the compiler can do in ways of inlining.

      Anyway, i ran the "method-call" test myself (with Microsoft VC6 compiler):
      100000 iterations:

      Original test took ~4500 kcycles
      Placing the objects on the stack instead of the heap brought it down to ~1900 kcycles (Note: this is what any decent C++ programmer *should* do)
      Using printf instead of cout brought the time further down to ~1300 kcycles (whether this is good or bad style is debateable).

      All in all, the tests only measure how well poorly written code can be optimised. Admittedly, it seems that the JVM does a better job than GCC here. I'll never believe that well-written C++ code can be outperformed by Java (Well written meaning that the programmer understands how the cache works, the costs/benefits of using virtual/inline/const functions etc. and most inportantly understands the data he is working with).

    7. Re:Command and source/test review. by arkanes · · Score: 1
      Right, it's virtual because the test is method call overhead, not how good the compiler/environment is at inlining away method call overhead. This makes the server JVM results basically usless for comparison to the others, even the client JVM.

      I just think this is a pointedly bad example because dynamic inlining is exactly the sort of case where you'd expect the JVM to have an advantage, but even in this case an apples to apples comparison isn't being provided. For example, in this case the JVM _could_ inline a virtual method call because the type is known. It can just recompile if the loop is called again with a different object. This is a clear example of JIT advantage.

      Certainly he shouldn't be claiming this as "Java outperforms optimized C++", but "Java can outperform generic C++". One of things about C++ is that, while it gives great control to the programmer, that control comes at the cost needing to optimize. The JVM will dynamically inline for you, with C++ the programmer needs to be aware of these issues and write his functions so that they can be inlined (no virtual method calls in tight loops), and allow the compiler to do so (-O3 instead of-O2).

    8. Re:Command and source/test review. by sht_london · · Score: 1

      std::string makes programming more convienent to write, but is not faster than an old-fashioned pointer to char. Normally direct manipulations of (char * ) are faster, but more diffucult to handle (memory leaks, allocation, free etc. pp.).
      Perhaps anyone can correct my: But so far I know the most std::string impementations use in the background the still (char *).

    9. Re:Command and source/test review. by Anonymous Coward · · Score: 0

      C++ strings:
      Know their size. Finding the length of a C++ string takes constant time.

      Perform lazy copying. Multiple strings can share char_type pointers until an instance is mutated.

      Use smart allocation behavior to reduce resizes when performing operations on string instances. Appending to a string doesn't involve reallocating memory for every append.

      All operations that involve copying string data benefit from constant size access. This allows you to use prefetching.

    10. Re:Command and source/test review. by Paradox · · Score: 1
      Since the function called is virtual, there isn't much the compiler can do in ways of inlining.

      This is outdated. The types of the arguments are known and fixed. The return types are known. The whole point of entering in all these tiresome type keywords (not to mention keeping them consistent) is to let the compiler do optimizations like this.

      The only time that the virtual part comes into play is when the type really is unknown within that block, like when it comes into a function call as a parameter. The fact that G++ can't say, "Oh look, a NthToggle is coming out of value() even though it's typed as Toggle" for such a simple case" is kind of depressing.

      I'd be curious to see if the IBM or Intel optimizing compilers could do that better. I know that other language compilers do this sort of thing, and in those languages all method calls are virtual.

      --
      Slashdot. It's Not For Common Sense
  249. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    Actually, /. doesn't like a whole lot of standard HTML formatting, so it would have spit up those codes anyway.

    The best solution is to just stay away from smart quotes altogether.

  250. Java Machine WAY faster then C++ by cryptoluddite · · Score: 1

    These results clearly show that Java is in the same league as C++, despite being slowed down by running in a C-based operating system. Just imagine how fast is would be if the OS was not so archaic.

    A safe, object-oriented operating system would make Java way faster than C++:

    • eliminates the penalty for context switches, so timeslices could be extremely short.
    • system calls would just be normal method calls instead of incurring the overhead of an interrupt. and they would be inlined like normal methods.
    • data would not need to be copied in/out of kernel memory.
    • if memory is sufficient then the code can run in real mode, without the overhead of using page tables / address translation.
    • even if virtual memory is needed, there's no tlb and cache flush overhead
    • since there's no need for separate memory spaces, creating a new 'task' (ie fork) would be nearly as fast as creating a thread.
    • the object in memory can be rearranged to reduce cache misses
    • the OS api could be much simpler and use more efficient approaches, such as using real callbacks (event listeners) instead of the crippled signal mechanism.

    and there are probably many more advantages. Take a system like that and run a C++ app on it (in a CVM) and you'll see it run orders of magnitude slower at best. C/C++ is just a much slower language than Java.

  251. Yep by Anonymous Coward · · Score: 0

    And Perl is faster than Java.

    And cows can fly.

    But seriously, Perl is faster than Java. ;)

  252. HAHAHAHAHAHAH by Anonymous Coward · · Score: 0

    Just roffel Ma friend!

  253. Re:Can I have an infinite budget to write the code by Bryan_W · · Score: 2, Funny

    Why not just use VB? It would have been the easiest and probably faster.

  254. Recursive Fibonacci measures method overhead by Anonymous Coward · · Score: 0

    By "optimizing" it you are circumventing the test, moron. Why don't you further "optimize" it and just print out the result?

  255. Come on! by TheLastUser · · Score: 1

    I thought this was /., where's the:

    "Linux beats Window$?"

    and don't forget that "$"!

    amd kills intel
    C# murders Java
    NT annihilates unix
    ascii obliterates ebsdic
    XML belittles html
    Mac redefines Windows
    SCSI uber alles
    bash trumps ksh
    csh cracks bash
    sv strangles bsd
    aix jack-boots sv

    and lets not forget:
    vt100 reins supreme over all other user interfaces that have been or ever will be invented!

  256. Ah, C++ ... by Crispin+Cowan · · Score: 0, Troll
    C++ has the safety of C, and the performance of SmallTalk :(

    There is no excuse for writing anything in C++ in this day and age:

    • If you are writing a kernel or an embedded bit whacker or a real-time thing, use C. C++ is too slow.
    • If you are writing an application, be it desktop, server, whatever, use Java or C#. C++ is far too unsafe.
    • If you are writing a rapid prototype, use PERL, or Python, or Ruby.
    My condolances to the KDE kommunity. It's a cool desktop & all (I'm typing on it) but bolting your whole framework on a C++ basis was a really unfortunate choice. It dooms KDE to long-term security vulnerabilities.

    Crispin
    ----
    Crispin Cowan, Ph.D.
    CTO, Immunix Inc.

  257. deciphering error messages. by pedantic+bore · · Score: 1
    It's true that aomeone who can't decode gcc error messages probably isn't a very experienced coder, but in this case we're really talking about g++, which is capable of emitting some amazingly baffling messages.

    But this is beside the point. To run benchmarks well a person must be diligent, methodical, and objective. Being a hacker is not a prerequisite. These benchmarks look a lot better than many I've seen. They might turn out to be flawed, but not for the reason you mention.

    --
    Am I part of the core demographic for Swedish Fish?
  258. *sigh* by ldspartan · · Score: 1, Troll

    So, I'm done with my CS degree from RPI, and I'd like to point out we're not all morons like this kid apparently is. Also remember he's just finished his sophomore year, and has probably just taken basic classes like Data Structures and Algorithms and Operating Systems.

    It just cheapens my degree, sadly.

    --
    lds

    1. Re:*sigh* by slandis · · Score: 1

      A little off topic here...

      I don't know Keith all that well, except to say I've known him for what seems like ages, and he's a very bright individual.

      Does he have a grudge here? Maybe. Does that mean he tilted everything and did a horrible job? Unlikely. I don't think he's claiming to be some super-dooper benchmark analyst, but he's provided the results from what his tests show.

      Calling him a moron based on this is pretty shortsighted of you, given that Keith never claimed these results to be absolutely evident of Java not sucking or anything.

      --
      BAM!
    2. Re:*sigh* by ldspartan · · Score: 1

      I consider understanding the basic aspects of the scientific method and what constitutes evidence to be required knowledge for anyone attending RPI. Also, other things like stating your biases and so forth are a bit of a requirement.

      Either he purposefully made the 'benchmark' biased towards Java, or he's incompetent. I'm betting he's incompetent, as I wouldn't want to attribute it malice.

      And that's okay. He's a second year CS student, and definitely not a computer scientist, yet.

      But if you publish results, and draw conclusions from data you've collected, under your name, you better have done a good job, or risk being called a moron. Look through these comments - the mistakes he made weren't subtle things. They were big, glaring, conceptual mistakes.

      He may be very bright, but he's no scientist. Not yet, anyway. Maybe he deserves the benefit of the doubt.

    3. Re:*sigh* by slandis · · Score: 1

      Did you visit his site, and not the one posted in the link?

      I'm not certain if Keith submitted his writing to the author of the linked article or not.. but Keiths site is pretty open to the idea that what he found was exactly that; what he found.

      He offers to post anybodys results, and other than the title (which is meant to grab your attention more than provide an ultimate truth), he simply that in HIS TESTING, Java proves to not be the slug everybody says it is.

      I'm not saying Keith is an award-winning computer scientist, but what I am saying is that he never claimed he was. I don't know if he asked for all the criticism (his 'article' originally appeared on his very own personal blog), but instead of calling him a moron, you could offer your advice as to how he might improve the tests he ran.

      Just a thought.

      --
      BAM!
  259. That's THE POINT! by Anonymous Coward · · Score: 0

    The fibonacci benchmark IS measuring function call overhead, Einsteins.

  260. Java == modern COBOL by NotZed · · Score: 2, Interesting

    Java works well as a COBOL replacement, a backend application language for boring buisiness apps.

    Thats what it should be benchmarked against. Comparing it to C is like comparing apples and oranges.

    --
    _ // `Thinking is an exercise to which all too few brains
    \\/ are accustomed' - First Lensman
  261. hash.c uses sprintf which is very slow by Serveert · · Score: 3, Insightful

    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.

    --
    2 years and no mod points. Join reddit. Because openness is good.
    1. Re:hash.c uses sprintf which is very slow by Serveert · · Score: 1

      meant to say that at compile time the java compiler knows it must invoke the hexadecimal conversion code.

      --
      2 years and no mod points. Join reddit. Because openness is good.
    2. Re:hash.c uses sprintf which is very slow by ruyon · · Score: 1

      Wow, how long has coding been a public service? Tell me your number and I'll give you enough bunch of code to fiddle with for months ;-)

    3. Re:hash.c uses sprintf which is very slow by /dev/trash · · Score: 1

      Isn't that what he's proving. Strongly typed languages will outperform those that are not. Out ot the box?

    4. Re:hash.c uses sprintf which is very slow by Anonymous Coward · · Score: 0

      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?


      Because strtol converts a string to a long, perhaps?

      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.


      I doubt the compiler optimizes away any check inside the toString() method because the second parameter is constant. It doesn't know it must invoke the hexadecimal conversion code, it just knows that it has to call toString with its second parameter being a constant 16. Of course, this can only be truly proven by examining the bytecode.

    5. Re:hash.c uses sprintf which is very slow by Anonymous Coward · · Score: 0

      Amazing how you people have a gut reaction to cry "slow!" the moment you see some runtime dispatching. Just how many instructions do you think it really takes for the sprintf main loop to see that the first character is '%', then check the next character and jump to the 'x' handler ?! Surely that will be lost in the noise.

    6. Re:hash.c uses sprintf which is very slow by Anonymous Coward · · Score: 0

      If your processor has a deep pipeline, conditional branches are among the slowest instructions. "Jump to the 'x' handler" will take more cycles than the actual conversion does.

  262. Java to Assembly by HopeOS · · Score: 3, Insightful

    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

  263. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    Assembly most certanly is graceful and elegant, used in the right hands. And if modern API's and architectures were designed for Assembly in mind, it would be the right tool for many jobs. But the fact is that isnt for a majority of cases.

    But try telling me Java is the proper language for a Z80 and I'd laugh in your face. I'd go as far to say C or C++ isn't even well suited in this case.

    You can reuse and mantain assembly with the same techniques you do with C or Java. You can also program less gracefully or elagantly.

  264. Oh Yeah? by Bill,+Shooter+of+Bul · · Score: 1

    Well the jerk store called, and there out of you!

    --
    Well.. maybe. Or Maybe not. But Definitely not sort of.
  265. Really? Try this one. by rjh · · Score: 3, Informative
    Given *any* algorithm, I can come up with a c++ implementation that is faster than a Java implementation. Period.
    I'd like to see a C++ implementation of the Halting Problem that's faster than a Java implementation, please, thank you.

    Oh, wait, you can't do that because nobody can write Halting.

    I guess that means there are some algorithms for which you can't write a faster C++ version. Next time, try less rhetoric and more facts. "There exist lots of algorithms for which I can code a C++ implementation that's faster than a Java implementation" is good. The instant you make a unilateral statement like the one you just made, though, it shows that you don't know as much about computer science as you think you know.

    Fact: there exist cases where Java is faster due to its ability to optimize on the fly. And if you know C++ as well as you think you do, this shouldn't surprise you. C++ beats C so handily for many tasks because C++ is able to do much better compile-time optimization largely on account of the C++ compiler having access to much more type information than a C compiler. When Java beats C++, it's on account of Java having access to much more information about runtime paths than a C++ compiler. ("Much more" may be an understatement; C++ doesn't even try!)

    In other words, the JVM (sometimes) beats C++ for the exact same reason that C++ almost always spanks C; the faster implementation has access to more information and uses that information to make more efficient use of cycles.

    I don't think these situations will appear all that often, and I am deeply skeptical of this guy's "in the general case, Java is faster" conclusion. But my skepticism isn't leading me to make rash statements which cannot be backed up.
  266. This is total BS by Anonymous Coward · · Score: 0

    Oh GAWD WHY! Why would you compare java to a piece of garbage like GCC??
    Even C# is faster than Java. IN fact, MS states C# is faster than MFC

  267. As Darth Vader would say: by Anonymous Coward · · Score: 0

    You don't know the POWER of the dark side.

  268. Re: EMACS/VI by Anonymous Coward · · Score: 0

    Both VI and EMACS will let you change characters in a file.

    EMACS will also let you browse the web, read netnews, ftp down files, read email, run arbitrary elisp software (eval-print-last-sexp in lisp-interaction mode), spell-check, font-lock, run your makefile, interactive-debug via gdb, etc.

    Anyone know if there's any truth to the rumor that somebody complained to RMS how wrong it was that emacs took up more memory than his kernel, thereby leading to the creation of the HURD project?

    EMACS
    = Editing Macros (old)
    = Escape Meta Alt Control Shift (new)

  269. Re:Caught up with the speed, but still the ugliest by mangu · · Score: 2, Insightful
    Yes, of course, the recursive Fibonacci is slow. But the point was measuring the efficiency of the compilers, not the efficiency of the code. Do you want a much faster Fibonacci algorithm? Here it is:


    double gold = (1.0 + sqrt(5)) / 2.0;


    int fibonacci(int n)

    {

    return floor(gold * n);

    }

  270. One mistake (Was: Re:Explanation) by jdennett · · Score: 2, Informative

    Almost no C++ implementation calls the OS (kernel) for every memory request, precisely because that's too slow.

    More to the point, C++ doesn't *have* to use dynamic allocation so often, but in badly written code it may well do so, and that will hurt performance. In C++ you can drop objects on the stack, in Java you can't. Heap/GC allocation can be pretty quick, but not quite as quick as stack allocation.

    1. Re:One mistake (Was: Re:Explanation) by Anonymous Coward · · Score: 1, Informative
      More to the point, C++ doesn't *have* to use dynamic allocation so often, but in badly written code it may well do so, and that will hurt performance. In C++ you can drop objects on the stack, in Java you can't. Heap/GC allocation can be pretty quick, but not quite as quick as stack allocation.

      Still, it's a case of C++ having some advantages and Java having some other advantages. Java can't put things on the stack, but the way it allocates objects is that dedicates a block of memory called "Eden", and just goes through it sequentially, allocating one object right after another, not doing any searching for available space.

      Then, because there are no native, machine-level pointers in Java like there are in C++, it is possible to move objects without screwing up references. So when "Eden" gets full, you can just compact the sequence of objects. Java uses a generational garbage collector that takes advantage of the fact that most objects are short-lived, which means that in most cases, Eden (the newbie generation of objects) will have a lot of objects in it that can be freed. Those that cannot be freed are recognizable as relatively long-lived objects and can be moved somewhere else, giving you a nice big block of memory that's once again free to use to allocate objects very quickly.

      The other thing Java has going for it is that all this can happen behind the scenes because objects can be moved and references changed without causing a problem. C++ can't do this. So, in many cases (such as when the application is blocked waiting for I/O), the Java garbage collector thread can actually get some work done that C++ would have to do either at the time you do a new or delete (i.e. inline instead of offline).

    2. Re:One mistake (Was: Re:Explanation) by ysachlandil · · Score: 1

      Well actually, if you use a compacting garbage collector, allocating stuff on the heap is exactly as expensive as allocating on the stack since the heap looks like a stack :)

      This is because the compacting GC moves all the live object to the beginning of the heap, therefore allocating heap is as easy as incrementing a pointer.

      See this page:

      http://www-106.ibm.com/developerworks/java/libra ry /j-jtp10283/

      --Blerik

    3. Re:One mistake (Was: Re:Explanation) by Anonymous Coward · · Score: 0

      Roughly right, but then the cost of deallocation is then much higher, and it's the allocate+deallocate cost that's interesting.

      On the other hand, GC can sometimes lead to better locality of reference, and help performance that way. And it *can* simplify designs a little, but not much compared to smart pointers in C++ (but then smart pointers have their own performance cost).

  271. Java performance "truths" change over time by eduardodude · · Score: 5, Informative

    Check out this recent IBM Developerworks article 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.

    1. Re:Java performance "truths" change over time by rebelcool · · Score: 1

      i'd say most people that post on slashdot know very little about the true nuts and bolts about languages and computers in general. No, writing a shell script does not mean you know a lot.

      Sort of sad, considering the audience it tries to appeal to.

      These kind of articles are trollish. Java is faster for some applications than C++, and for others C++ is faster. It depends on what you want to do with it.

      I think java continues to improve its performance and feature set though, with every new version that comes out every couple of years. C++ is more or less into its mature, sunsetting years and not likely to have any revolutionary, or even major evolutionary, improvements.

      --

      -

    2. Re:Java performance "truths" change over time by Anonymous Coward · · Score: 0

      over the last 2 years, IBM's researchers have done a tone of great work on improving garbage collection. Just google for Virtual machines and you'll see there are a lot of articles in peer review journals that show how fast JVM's can be. In fact, the latest generation of JVM's are highly optimized.

    3. Re:Java performance "truths" change over time by Anonymous Coward · · Score: 0

      Sun estimates allocation costs at approximately ten machine instructions

      Ghee, I'd like to see how they do that. They must be talking about allocating on the stack, because I don't see how you could do this for 'new'...

    4. Re:Java performance "truths" change over time by Anonymous Coward · · Score: 0

      Read up on generational garbage collection. Allocating there is really a matter of advancing the free space pointer, checking against the gc trigger and in the likely case that gc isn't needed, you're done, in ten instructions or even less.

  272. No, no! EMACS is only the kernel! by mangu · · Score: 1

    And the correct name is "GNU/Emacs"!

  273. Re:This doesn't make any sense... by Anonymous Coward · · Score: 0

    Some emulation systems have used persistent, offline translation. For example, FX!32 (I think I have the bang in the right place) enabled running x86 Windows binaries on Alphas through a combination of interpretation and static (off-line) translation. Frequently-executed parts of the program would get translated to Alpha code and saved to disk.

    One of the main arguments against going to disk is that generating a dumb translation is often as fast as or faster than finding an existing translation and paging it in from disk.

    For a long-running application, saving to disk doesn't help a whole lot, since you eventually get an optimized version of everything important anyway. And if your application runs quickly enough that startup time matters, it's probably fast enough already.

  274. However, C++ is faster to LEARN than java by RLiegh · · Score: 2, Funny

    at least if you already know C.

    1. Re:However, C++ is faster to LEARN than java by thepr0fess0r · · Score: 1

      If you know C, I would still say that Java is faster to learn than C++

    2. Re:However, C++ is faster to LEARN than java by nevets · · Score: 1

      I would disagree. C++ still lets you write C code. Hell, at my old job, I was put on a project that was using C++. When I started, I had to tell them that they were not writing C++, there were only using a C++ compiler for C. When I starting changing things to use objects, people started freaking out.

      I'll change your statement: Java is easier to teach you Object Oriented programming if you already know C, than C++.

      That said, I haven't used java for years and should try to learn it again. When I started to learn it the first time, it was still new and the libraries seem to change every month. So I got fed up with it and never came back. A colleague of mine told me things are now stable and I might try it again. But I'm a systems programmer, so it isn't necessary for me to learn it quite yet. Maybe if I get bored, I'll give it another go at it.

      --
      Steven Rostedt
      -- Nevermind
    3. Re:However, C++ is faster to LEARN than java by thepr0fess0r · · Score: 1

      That's why java is so much faster to learn if you already know C... in C++, if you don't feel like learning, you can just fall back on C as a crutch. I'm not saying that having C as a subset of C++ is a bad thing, I certainly use it *all* the time, however, having it there doesn't help you to learn C++ any faster (and in fact slows you down!)

  275. Get with the program by twoslice · · Score: 0

    The language of the week is Assembly language...

    --

    From excellent karma to terible karma with a single +5 funny post...
  276. Hey, this thread is about CONTROVERSY! by mangu · · Score: 1

    you mentioned a fact where *everybody* agrees.

  277. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0
    "Java will never be faster than properly optimized C++ compiled with an intelligent optimizing compiler except[...]"

    Utterly false!

    Java has 2 big advantages over C++

    1. as a more restrictive language, it doesn't have the issues of aliasing (multiple objects occupying the same memory), so the Java optimizer can make more aggressive assumptions about what can be reordered and precalculated.
    2. as a JIT-compiled language, Java can gather profilling statistics before generating the machine code. C++ could do a profiling pass first, but people rarely do this; and the profiling runs of C++ programs are often not real-world cases so the program flow may be different.

    Even garbage collection is an advantage rather than a disadvantage, because while C++ needs to free up every little allocation one-at-a-time; a garbage-collected heap can do many-at-a-time.

    The only reason Java is slower than C++ is that C++ compilers are more mature.

  278. Re:This doesn't make any sense... by Omnifarious · · Score: 1

    I find Java's container libraries to be annoying and obtuse. I prefer the STL or Python's containers.

    Java's containers lacked an iterator concept until recently, which made it hard to have code that went through a random container independent of its type. And Java's lack of support for generic programming makes use of their containers very cast heavy.

    The standard UI library, Swing, is too slow to be used for actual real work. And they stopped bothering with the X event model in Java 1.3, so it's impossible to run Swing applications in a remote X session with any speed at all. Every twitch of your mouse results in a flood of network packets to the Java application, which it then has to carefully process.

  279. Client JVM by Brandybuck · · Score: 1

    no one should ever run the client JVM when given the choice

    That's a pretty damned big caveat when you think about it. I can hear the excuses now... "Of course it seems like Java is slower than C++, you're running it on the client! Duh!"

    --
    Don't blame me, I didn't vote for either of them!
  280. Convergence by Renaissance+2K · · Score: 1

    This is not going to be the most specific post in the world because I don't have the original source nearby, but...

    In the most recent issue of Maximum PC, an experienced programmer wrote in to defend a recent tutorial on how to program in Visual Basic. He said that with the emergence of the .NET framework, the difference in performance from one programming language to another is negligable at best. Hopefully, someone else out there read the magazine and can elaborate on his statements, but I think it's an interesting point nonetheless.

    1. Re:Convergence by Anonymous Coward · · Score: 0
      He said that with the emergence of the .NET framework, the difference in performance from one programming language to another is negligable at best.

      That's simply bullshit. VB.NET has nothing to do with VB; it is largely equivalent to C#, so this doesn't prove anything. And highly dynamic languages like Perl or Ruby will *always* be slower because the dynamic features (method lookup by name, for example) necessary impose a larger runtime overhead.

  281. Metrics by Anonymous Coward · · Score: 0

    I use Java everyday at work- its my job. But at home I use C/C++ because it loads quickly and executes quickly.

    Java has its uses, but the problem is that Java isn't platform specific. IE: its intended to be bytecode and yes, you may have some program that compiles java into native code and it executes very fast. But your user must run JVM X version Y with mode M, and have 32 megs of ram free for the Java environment to load. If you are writing a commercial application, and you are serious about your company, you're going to use C/C++ and optimize your code natively for the platform you execute on.

    My buddy and I have this discussion periodically- he uses a Java based IDE and I use a C based IDE. His IDE takes about 10 seconds to load up when he double clicks a java file, mine takes about 3. Once loaded, they both perform similar but mine seems to respond slightly faster. He is happy to wait, I am not. I use Slickedit, he uses Netbeans.

    I wish I had a dime every time someone said "yea, well Java is a great game platform" and my response is- "Obviously. All the best selling games are written in Java, as is the best selling operating systems"

    Java is fine for what it does, but given byte code or native code, I will always choose native code. I don't want a JVM.

  282. Re:Caught up with the speed, but still the ugliest by SparafucileMan · · Score: 1

    I would like to add that, while already-loaded JAVA is just as fast as C or whatever, JAVA is an ugly, stupid language. Being forced to use pseudo-object-oriented style with libraries that are hopelesley disordered (both litterly and linguistically) is no fun, period. It takes way too much time to write code in JAVA and results in code forced to a particular methodology, one that isn't even that super to begin with. I don't udnerstand why people dick around with this language when they could use a purely functional one and get not only functional style, but OO and procedural and continuations and better debugging and better, quicker writing of code, as well. The only thing Java has accomplished is getting swarms of incompetent, corporate-whore programmers to work together on software without requiring the use of a brain. And yes, I am a corporate-whore programmer, so I know this is how it is.

  283. C++ 60X Faster Than Java by Zan+Lynx · · Score: 2, Interesting
    I was confused by this article, because I know Java is slower than C++. I took one of the programs, the Ackermann function, and figured out what was happening.

    The Ack function was being called over and over with the same arguments. A little work with an STL map, and I created a cache for the function arguments and results. I think this is called memoizing a function.

    Here are the results when I finished:
    $ time java -cp java ackermann 13
    Ack(3,13): 65533

    real 0m29.620s
    user 0m25.180s
    sys 0m0.292s

    $ time ./ackermann 13
    Ack(3,13): 65533

    real 0m0.479s
    user 0m0.228s
    sys 0m0.017s
    1. Re:C++ 60X Faster Than Java by khuber · · Score: 1
      The Ack function was being called over and over with the same arguments. A little work with an STL map, and I created a cache for the function arguments and results. I think this is called memoizing a function.

      How fast is the cached java version?

      This could be better.

      private static Map cache = new HashMap();
      public static int Ack(int m, int n) {
      String key = m + ":" + n;
      Object cached = cache.get(key);
      if (cached != null) return ((Integer)cached).intValue();

      int x = (m == 0) ? (n + 1) : ((n == 0) ? Ack(m-1, 1) :
      Ack(m-1, Ack(m, n - 1)));
      cache.put(key, new Integer(x));
      return x;
      }
    2. Re:C++ 60X Faster Than Java by Zan+Lynx · · Score: 1
      After your change, I get this:
      $ time java ackermann 13
      Ack(3,13): 65533

      real 0m4.223s
      user 0m0.493s
      sys 0m0.026s
      So, it's faster, but still not as fast as C++.
    3. Re:C++ 60X Faster Than Java by khuber · · Score: 1

      Thanks for timing it! I'm okay with C++ being faster, just not 60X faster :).

    4. Re:C++ 60X Faster Than Java by PhilHibbs · · Score: 1

      Memoizing a function in Perl is even easier:


      # This is the documentation for Memoize 1.01
      use Memoize;
      memoize('slow_function');
      slow_function(arguments); # Is faster than it was before


      This is just one of the advantages of a compile-on-demand language.

      Being an old C hack, I can't help believing that C or C++ should be faster than Perl, but every time I get around to writing equivalent programs and testing them, I find that I am wrong. I'm sure that if I did something purely CPU-intensive, then I would find C or C++ to be the winner, but most of my examples have been I/O based, and perl kicks ass for I/O.

    5. Re:C++ 60X Faster Than Java by Zan+Lynx · · Score: 1

      Since you mentioned Perl, just for fun I made a Perl version of this Ackermann program. I used the Memoize module. It runs about the same as the Java version: 4.8 seconds.

    6. Re:C++ 60X Faster Than Java by PhilHibbs · · Score: 1

      That is unsurprising to me, as it is primarily computational. The only scope for Perl to win is in the print statement, and that's fairly simple. The function call overhead is a factor as well, which is another place where I would expect C to win (register optimisations). I would be interested to see a non-recursive implementation, which I would still expect C to win on.

    7. Re:C++ 60X Faster Than Java by PhilHibbs · · Score: 1

      The advantage of the Perl Memoize module is that you don't need to change your function or the code that calls it - it's transparent and easy to remove, almost as simple as a -O switch to the compiler.

      Some might say it's too easy - just make sure that you don't accidentally memoize a function that has other effects than just to return a value, though, such as I/O!

  284. 1.5 JVM improvements likely to impact speed by eduardodude · · Score: 1

    Check out Class Data Sharing.

    "The class data sharing feature is aimed at reducing application startup time and footprint. The installation process loads a set of classes from the system jar file into a private, internal representation, then dumps that representation to a "shared archive" file. During subsequent JVM invocations, the shared archive is memory-mapped in, saving the cost of loading those classes and allowing much of the JVM's metadata for these classes to be shared among multiple JVM processes."

    It's only enabled for the client VM. Incidently, it was developed and submitted to Sun by Apple.

    1. Re:1.5 JVM improvements likely to impact speed by Anonymous Coward · · Score: 0

      Moreover, having tried some GUI tests on 1.5 the -server option actually makes somethings slower.Especially the creation of SWING components, I don't know about other GUI toolsets. So I think maybe this whole -server thing may not be relevant to 1.5.

  285. Nope by Anonymous Coward · · Score: 0

    C++ sucks cocks

    1. Re:Nope by Anonymous Coward · · Score: 0
      C++ sucks cocks
      ..that smell? ..in hell?
  286. Lies, damn lies... by Tracy+Reed · · Score: 1

    ...and benchmarks. We all know by now how this works. In my particular, unique, case I only have two real-world applications for java. Freenet (http://www.freenetproject.org) and Invisible Internet Project (http://www.i2p.net) It is by coincidence they are both written in java. They are both incredibly cpu and memory intensive. They both have native jni add-ons to speed things up and these native implementations are often many times faster. I suspect the cases where native is much faster still greatly outnumber the few instances where java is faster.

  287. Bunch of wining bitches by Anonymous Coward · · Score: 0
    It's so funny to read all your dumbass complaints about how it's not a fair test, the C code wasn't optimized, it was only a language comparison, blah blah blah.

    It was only a matter of time before dynamic execution outperformed static compilation. Wake up and smell the Java.

  288. Re:This doesn't make any sense... by jrivar59 · · Score: 1

    This feature (persistent caching of core library classes) is in tiger (1.5). I haven't benchedmarked 1.5, but startups of some of my favorite apps are noticably faster. Debug, compile and test cycles seem to be about the same for me though...

    Read about it here.

  289. Same for hash.cpp by Tim · · Score: 4, Interesting

    I'm futzing around with the other hash benchmark, and sure enough, making only a trivial change to the code (eliminating the unnecessary strdup in the second hash lookup), gets me about a 30% improvement in performnace.

    This guy is a tool.

    --
    Let's try not to let fact interfere with our speculation here, OK?
    1. Re:Same for hash.cpp by Anonymous Coward · · Score: 0
      This guy is a tool.
      This is by far the most insightful comment posted to this article.
  290. I wish I could USE Java for anything real by pabtro · · Score: 1

    Today I spent the whole day trying to parse a 2M plain text document using the regular expressions feature in Java 1.4. I could not get anything done, the thing just crashes. I wanted a "portable" solution very dearly, and I wanted to "do" Java. Sorry, but, like every other time, it just doesn't work. I bought all these books; I really like Java. I just can't get anything done with it in a reliable way without recurring to some sort of trick, or following some "the right way to do Java" advise/book/article. I have not tried other solutions, like Perl or Python, but I am not taking any risks; I'll just settle for C++ and plain finite state machines for now. Nothing better than a tool that works well every time.

    1. Re:I wish I could USE Java for anything real by Anonymous Coward · · Score: 0

      that sounds funny. I've written several parsers in the past to parse network and server logs ranging from 10-50Gb. It didn't take more than an hour to write and test it. That's not to say java is good. what it does say is I tend to think in java terms. If I had to do the same thing in another language, most likely I would have a much harder time and curse the language. I've seen some amazing perl scripts that I couldn't have written even if i tried. my point for what it's worth is not everyone thinks the same and not everyone can be good at every language.

  291. Yay by Anonymous Coward · · Score: 0

    Glad I'm learning Java. Of course I've heard that its slowness was a drawback, but I also heard that they're trying to make it faster.

    Maybe its supposed slowness was largely a misconception?

  292. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    The code? Hard to believe without it.

  293. That's all true.. by mindstrm · · Score: 2, Insightful

    but that's nto the same thing as saying "Java is faster than C++". The benchmarks in question are bout execution speed, not development speed.

    Some of the benchmarks could have been far better implmented with code no more complex than what was arleady used on the c++ side... that's the issue here.

    "java is faster for lazy coders" is a fair statement.. but not really what a benchmark tries to asess.

  294. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    Are you me?

    Because I could have swore I was thinking the same thing, except that I am a currently uemployed CWP.

  295. Speed bigots! by t'mbert · · Score: 1

    Is it just me, or have there been alot of responses that boil down to "C++ can be fast if you throw away anything inherently C++ and use straight C instead?"

    Part of the point here was to compare two supposedly similar languages. If the author wanted to compare nasty optimized hard-to-read C to Java, he would have.

    Java, and .Net too, are great because they are rich, more than anything.

    If you really care about speed so much, why are you running an OS to run an application that is a language interpreter (HTML, in this case), the code of which was produced by yet another interpreted program (Perl) that runs through another program (Apache) on top of yet another OS, and which is transported over a low-bandwidth internet connection?

    Because it's feature-rich!

  296. Not silly at all by GCP · · Score: 3, Interesting

    I don't deny that the finer granularity of C++, no make that plain C, no make that raw assembly language, allows you to make certain optimizations that are quite valuable in certain circumstances.

    But when you are trying to choose the right tool for a particular job, you need to be current on the details of just what advantages, and what degree of advantage, and in what circumstances, comparing current versions of all of the candidate tools.

    This benchmark seems to be showing that things don't just remain the same. That, in fact, the circumstances in which C++ is a better choice than Java are becoming fewer and the advantage in those circumstances is becoming less.

    The fact that Java VMs are primarily written in C or C++ indicates that at the time they were initially written, it was believed (I think correctly) that the C or C++ at that time would be a better platform for writing JVMs than the Java of that time, and that since then it has been considered better to extend the existing code than to scrap it and do a complete rewrite in Java.

    That's all that this argument proves. Nothing more.

    What I'm saying, though, should not be interpreted as a belief that today's Java would be a better choice than today's C++ for writing a Java JVM. I don't know what the relative advantages would be today.

    But if C++ were STILL the best tool for writing a JVM from scratch today (certainly possible), that wouldn't mean much when trying to choose a tool for your own app, because most apps bear very little resemblance to a JVM.

    --
    "Those who have never entered upon scientific pursuits know not a tithe of the poetry by which they are surrounded."
    1. Re:Not silly at all by Anonymous Coward · · Score: 0

      Hm...

      So assuming that you might come to the conclusion that Java is faster than C++ for writing your JVM, I want to hear your opinion on the following : I use Java (running on a JVM, call it JVM1), to code a JVM (call it JVM2). What then is JVM1 written in ? C++ ? So maybe if we simulate once more, a JVM running on a JVM running on a JVM running on C++ we might get further speedup ? Ofcorse not. I think it is safe to say that if your JVM is written in C++, then at least the subset of the language that was used must be faster than the JVM itself.

      If the benchmarks really show that the JVM is faster than C++ code, I would assume that a JVM was written in C.

  297. Re:Can I have an infinite budget to write the code by Anonymous Coward · · Score: 0

    Your post reads as if each difference is a point in java's favour, which I don't really see. Perhaps you didn't mean it that way, but that's how it sounds. Really, most of your post sounds more like "I'm more familiar with java, therefore it's better".

    C# has one major IDE (Visual Studio) which has a RAD philosophy which *does* prevent some valid C# code being written.

    Such as?

    The IDE is really buggy

    Not buying it - I've used the IDE for several months and not had a single problem with it. SharpDevelop had some bugs, but the MS IDE has not caused me a single problem. Do you have examples?

  298. Re:Caught up with the speed, but still the ugliest by saden1 · · Score: 1

    If this person doesn't know what the error messages mean or where to look to find out then it is safe to assume that they are not capable of writing optimized code. Just look at his hash code. He uses a strcmp function in the c++ code to perform string comparison where as java uses hash based comparison in containsKey function. The fact that Java keeps track of table of hash codes in memory helped its performance tremendously. The code structure isn't consistent either.

    One can clearly tell that the gentleman is not experienced in writing optimized code.

    --

    -----
    One is born into aristocracy, but mediocrity can only be achieved through hard work.
  299. awful presentation by boots@work · · Score: 1

    Leaving aside the results or whether the benchmark is meaningful, his presentation of the results in the graph is truly awful. The one large spike for Method Call/Server JVM is so large that all the other results are nearly visually indistinguishable.

    He admits he couldn't write a script to automate the tests. That does not inspire confidence in his ability to assess programming languages.

  300. C/C++ slower than Java?? by Anonymous Coward · · Score: 0

    Please.....

  301. Theory and practice: run-time optimisation by Anonymous+Brave+Guy · · Score: 1

    I certainly agree that running on a VM with JIT compilation should theoretically be a comparable speed to pre-compiled code (other things being equal). However, I think many people here are putting way too much faith in dynamic optimisation at run-time.

    Sure, the VM could watch the code for the most-executed paths and re-optimise for them on the fly. Of course, that's pretty much equivalent to active profiling the first few runs through the code. As anyone who's waited while an instrumented executable profiles a large data set at 1/10 or less of its usual speed can tell you, active profiling is slow. In order to be of any real value at all, you'd have to run-time optimise only the most frequently executed code, with a good choice of how many runs to profile before you recompile it. Anything else is just never going to give you a worthwhile return on your "investment" in profiling overhead.

    Basically, there are plenty of theoretically sound and practically evident ways for a VM/JITC approach to be as fast or even faster than a traditional compile-only approach, but run-time optimisation is not one of them; it's much more hype than silver bullet.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  302. Re:Some performance myths by Anonymous Coward · · Score: 0
    g++ sucks big time ... almost always 20->30% faster than g++ ... spectacular ... as much as 30%
    Wow. A whole 30%? Am I supposed to be impressed? A compiler whose output runs 77% as fast does not "suck big time." While you may notice a 30% difference in a head-to-head test on a lengthy process, you will not be able to tell the difference for most applications. To see what I mean, head down to your local computer store and fire up your favorite application on a 2.4 GHz and a 3.1GHz machine. Have a friend switch the monitor/keyboard with a kvm switch. You're not allowed to use a stopwatch, and you have to wait at least 1 minute between the tests. Your challenge: correctly identify the two machines. I'll bet a coke that you can't do it.
  303. Truely optimized c++ code by nukem996 · · Score: 1

    As a gentoo user, C++ and Java programmer I was very interested in this. I noticed one thing though, this "optimized C++ compile command" was only a generic i386/i686 command. I reran the tests with the optimized compile command I use as my CFLAG g++ in.cpp -march=pentium4 -O3 -pipe -fomit-frame-pointer -o out. After doing this I got C++ to come out faster 75% of the time. Probably if I played with the code and optimized the C++ code as well I could get it to run faster. I emailed the author my complete results. If you would like to see them just reply here with your e-mail.

    1. Re:Truely optimized c++ code by realJJ · · Score: 1

      Could you please send it to me at cchany@sfu.ca? Thanks very much.

  304. never underestimate the cost of stream sync by emarkp · · Score: 2, Insightful
    The cout is done twice, and the new and delete are each done only once. They are not the reason for the poor performance.

    Sure cout is done twice, but it uses 'endl' where '\n' would do. 'endl' flushes the stream, which pretty much kills cache behavior. When the disk/console is orders of magnitude slower than the CPU, a single 'endl' can indeed kill performance.

    As for new/delete, they can also be very slow, depending on the current memory layout, etc. More importantly, they violate the C++ programming paradigm (local objects not allocated on the heap) and hence are indicators that this isn't a very good C++ programmer, and hence he isn't qualified to make a reasonable comparison.

    Shoot, the last time I did the Java/C++ flamewar I found that Python was faster than both (reading and sorting strings).

  305. Come on, come on... by Lucky+Luc · · Score: 1

    You know guys benchmarks are nothing but gummy bears for vendors and customers! Everything affects a benchmark: programming style, programming skill, TIME spent optimizing the code, machine load, cache size, cache speed, compiler switches, compiler optimisation techniques... and so on and so on... Reduce the struct from 5 bytes to 4 and more blocks will potentially fall on cache, boosting the speedup factor. If you don't have a clear, at LEAST, 50% gap, it's "in the noise" of statistics and not worth even looking at it.

    If you want a real benchmark, ask Blizzard (http://www.blizzard.com) to code their next Warcraft IV game in 100% Java. Personally, I put my bet on C++... ...well for now. ;)

  306. Re:Programmer productivity is a more important met by pclminion · · Score: 1
    I can't find pointers to those studies right now.

    Java doesn't have pointers, thus your difficulties.

    Anybody got some references?

    Now, references we can handle. Haha, get it?! Handle! Hah! Okay, nevermind.

  307. Re:That's not quite the point by Anonymous Coward · · Score: 0

    Actually, no it is not. The Fibonacci benchmark measures the language's ability to turn tail recursion into iteration. The Ackerman benchmark measures actual recursion, since a compiler cannot remove its nested recursion. For what it's worth, ocaml wins both the Fibonacci and Ackerman benchmarks by fairly wide margin (Fib: 2x faster than gcc, Ack: 33% faster than gcc). (Disclaimer: I'm no fan of ocaml -- I've never used it. I'm just reporting the facts.)

  308. I'm getting too old for this crap by Prong · · Score: 1

    For fooks sake,

    I really wish people who develop this mildly insane desire to compare "speed" between languages would at least bother to aquire the compilers and expertise to fairly run the benchmarks.

    Mark me redundant, but the Gnu suite has never been about performance, while the Sun JVMs are all about how fast what amounts to an interpretive language can actually run. Side note: IBM's JVMs still smoke Sun in real world apps.

    You want to make useful comparisions? Benchmark .Net c# on doze vs. Sun's JVM on equiv intel hardware. That's real world, and a hell of a lot more relevant to the (F)OSS community.

  309. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 1, Informative

    You've got it wrong. This is correct:

    const double sqrt5 = sqrt(5.);
    const double gold = (1.0 + sqrt5)/2.0;
    const double goldi = (1.0 - sqrt5)/2.0;

    int fibonacci(int n)
    {
    return floor((pow(gold, n)-pow(goldi,n))/sqrt5);
    }

    For n > 5, you don't need the goldi part.

  310. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    "And if modern API's and architectures were designed for Assembly in mind"

    you just have no clue huh?

  311. Re:That's what happens with the lowest common GUI by Anonymous Coward · · Score: 0

    he said pretty, wtf was that?

  312. Re:Can I have an infinite budget to write the code by xynopsis · · Score: 1
    Have you even heard of this thing called "Qt"?. Unless you've been living under a rock for years, it is a C++ multi-platform toolkit that offers almost everything Java has: a garbage collection-like mechanism(QObject parent-child relationship), Excellent GUI (take a look at KDE), threads, networking, sockets, containers, almost everything under the sun! With one exception: it is built on the raw power of C++.

    As mentioned on a previous post, the reason why the C++ test are too slow is because the person who wrote the benchmarks don't even know how to write "proper" C++ programs. Using cout instead of printf for debugging purposes, repeatedly allocating objects within a loop. Native Qt programs can easily beat your Swing-based semi-interpreted app any time.

  313. Narcoticized slug faster than SR71 by Anonymous Coward · · Score: 0

    Maybe in someone elses world, Java is faster than C++, and maybe in their world a narcoticized slug is faster than an SR71 Blackbird (with afterburner) in their world. Not in mine. I've seen real-world java running on my real-world computers. I've seen real-world C++ running on my real-world computer. In my world, Java runs like a narcoticized slug. It's slow as hell. I've heard stories of 'pre-compiled byte code that's real fast'. Bullshit. Fundamentally, java is interpreted and has a middle layer between itself and the machine it's running on. C++ compiles into the machine code the local processor directly understands. If you say 'Java has new algorithms...' I can argue "I can put those into C++". Java is slow. C++ might not be the fastest language for every application, but for most, it's usually close to an order of magnitude (ten times) as fast as Java.

    1. Re:Narcoticized slug faster than SR71 by 09za+ · · Score: 1

      If you're selling advertising space, wouldn't a little extra time for the peeps to the ads be a good thing?
      Purists remind me of cross country mountain bike racers...they impune Downhillers as lazy and unfit when nothing could be further from the truth.
      Coding in Javascript is simple and easy to learn by the myriad of downloads to be found cluttering the net.
      I got my first computer in feb.(pathetic... I know...I'm A downhill racer)and I already have pages in Javascript that amazed my family and friends as well as the the bike shops and manufacturers who are going to pay me to advertise on my site... once I get around to PICKING A HOST. I must at this point thank Premshee Pillia for his awesome examples as well as Codefoot. We can't all be programming wizards, some of us have construction work to do and races to top 5 in at ski Plattekill.
      I'm sure it must be faster to program things in blah,blah,blah, but to average people and average CUSTOMERS it is mostly irrellavent (IMO).

  314. Re:Can I have an infinite budget to write the code by Arroc · · Score: 1

    Qt's X11 GPL version is free. A commercial license is not.

  315. Re:Can I have an infinite budget to write the code by Anonymous Coward · · Score: 0

    c# has fucking xml gobbledegook interspersed with C++/Java style code.

    What? "XML gobbledegook" is not a requirement. Please smoke less crack.

  316. Re:Can I have an infinite budget to write the code by Anonymous Coward · · Score: 0

    C# isn't portable.

    Oh? That depends on your definition of portable.

    If your definition is "one set of code can be run on any machine", then neither C# nor Java is portable.

    If your definition of portable is "it's possible to create a runtime and compiler that will support the language", then C# is equally as portable as Java.

  317. Re:This doesn't make any sense... by Anonymous Coward · · Score: 0

    Java's containers lacked an iterator concept until recently

    Until *recently*? The iterator support has been in place since at least 1.3, so it's been there for quite a few years now.

  318. Re:Can I have an infinite budget to write the code by Arroc · · Score: 1

    And Visual Basic is even easier to use for creating simplistic GUIs, but that doesn't mean that it is better.
    Qt's lack of basic design patterns, notification mechanism, relatively poorly designed widgets and lack of flexibility makes implementing anything that goes out of the ordinary a nightmare. The sad part is that Swing is also far from perfect and they are both still among the better GUI packages. I hope SUN rewrites Swing from scratch while keeping its philosophy.

  319. Java Method Call Performance by Anonymous Coward · · Score: 0

    I am surprised about the Java method call performance being so much better than C++. That tells me something weird is going on here.

    Java has a LOT of method calls to methods containing only 1 bytecode, which would be trivial to inline. In fact, a lot of Java methods contain only a few bytecodes. So the cost for these methods is close to 0 as the JIT inlines them. Could these methods be tipping the results in favour of Java too heavily? One should probably look at the median instead of the mean speed of method calling. What is the worst case calling speed for Java/C++ ? What if we strip out the outliers?

    These benchmarks definitely surprise me. The JIT trashes the cache when compiling methods, and uses a lot of RAM. I know for a fact that cache performance is going to be terrible under the JIT compared to C++. But what difference would that make in these benchmarks?

    I'm looking at Java traces right now, and a very small program that does almost nothing contains 15,600 method calls. About 12,000 of that is just API stuff before main is even called. It generally calls the same methods over and over again (e.g. <init> on object, etc etc). This is why the startup time for Java is so horrendously slow.

    I don't know, these benchmarks just seem to go against my own experience.

  320. Re:my arse by kaffiene · · Score: 1

    That's a single branch - true / false - so you can take two paths at once. That's not what I'm talking about (and it's not a differentiator between Java / non-java code anyway).

    Runtime constants are things a user-supplied value you multiply each cell in a large array by - instead of loading the value from memory, you could use an immediate value.

  321. laughing.. by joeldg · · Score: 1

    I always look at these "my car is faster than your car" things.

    C is 'the' language.
    Assembly is faster (for obviously reasons)

    You cannot write a java compiler in java, it is written (and funny, that) in this case in C++

    soo.. I would say your benchmarks are probably problematic and not taking enough time or crunching enough data or something.

    It is nice that you are all into your language that (in my personal opionion was nothing more ever than a buzzword that got out of control) but really now.. You do realize that slashdot would not print a "C is faster than Java" story because most people already know that, they posted your story because they know that about 100 people will post benchmarks that will make you crawl back in your java hole to lick your wounds.

    But, that is just my opinion on this grumpy night..

    1. Re:laughing.. by demon · · Score: 1

      You cannot write a java compiler in java, it is written (and funny, that) in this case in C++

      That must be some mighty strong crack you be a-smokin' there. You do realize that the Sun Java compiler (aka javac) is written in Java, don't you? Please go download the Sun or IBM JDK and look for yourself - javac is just a wrapper that calls a class in the com.sun.tools.javac namespace to start the Java compiler. Now no more talking out of turn...

      --

      Sam: "That was needlessly cryptic."
      Max: "I'd be peeing my pants if I wore any!"
  322. you have no idea what you're talking about by autopr0n · · Score: 2, Informative

    Are you trolling or what?

    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.

    No it's not. In fact, it's not even close to the definition of the "halting problem". The Halting Problem is "Given input X, and program Y, will Y ever finish it's calculation, and halt on when given X as an input". It's a 'problem' for which no computer program can be written to solve.

    It has nothing to do with whether or not a compiler can convert a recursive algorithm into a non-recursive one.

    That it's possible to convert looping programs into recursive programs is trivially true, because recursive functions alone are Turing complete. Similarly, because any recursive program can run on a Turing machine, which has no concept of a 'stack' needed for recursive calls can run any recursive program by emulating the stack on it's tapes.

    If you want a real world example, just compile any recursive code in any language to MIPS or some other RISC instruction set without push/pop and call functions like those found on X86 chips. You don't "call" functions directly, you just move around in memory and jump all over the place, just the same as you would in looping code.

    --
    autopr0n is like, down and stuff.
    1. Re:you have no idea what you're talking about by Ninja+Programmer · · Score: 1, Informative

      Are you trolling or what?

      I am a professional programmer with plenty of math background. Besides running a porno-site, who are you?

      This is known as the "halting problem". ...

      No it's not. In fact, it's not even close to the definition of the "halting problem". The Halting Problem is "Given input X, and program Y, will Y ever finish it's calculation, and halt on when given X as an input". It's a 'problem' for which no computer program can be written to solve.

      I didn't say its the definition of the problem. But you clearly don't understand how this definition applies to the real world. For any algorithm to determine whether or not a recursion has a simple degeneration to an iterative formula requires solving arbitrarily complex math problems.

      Solving or knowing if these math problems can be solved is equivalent to the halting problem.

      The point is that the best compilers can do here is pattern matching which isn't going to be worth it for the relative infrequency of any given special cases.

    2. Re:you have no idea what you're talking about by timeOday · · Score: 1
      Well, I know the halting problem and I don't see how it relates to what you're saying. The conversion from recursive to iterative isn't arbitrarily complex, it's simple and mechanical. The easiest way is to simply use a stack to maintain the state of what were previously recursive calls. Then there are other more clever and efficient ways in most cases too. But you can always use the stack trick, which is just what the "recursive" language normally does behind the scenes anyhow.

      Anyways, all the halting problem implies is that an optimizer will never be able to find every situation where a particular optimization is applicable. But the exceptions might be obscure corner cases. But in any case it doesn't imply that converting from recursion to iteration is impossible, or even difficult.

    3. Re:you have no idea what you're talking about by Anonymous Coward · · Score: 0
      I am a professional programmer...
      This post would have been much better if you said that you were a ninja programmer.
    4. Re:you have no idea what you're talking about by Deliberate_Bastard · · Score: 3, Insightful

      I'm sorry, but I am afraid you are wrong.

      Well, I know the halting problem and I don't see how it relates to what you're saying. The conversion from recursive to iterative isn't arbitrarily complex, it's simple and mechanical. The easiest way is to simply use a stack to maintain the state of what were previously recursive calls.

      This is still recursion. You have simply substituted one stack for another.

      Anyways, all the halting problem implies is that an optimizer will never be able to find every situation where a particular optimization is applicable.

      No, it implies much more than this.

      Deciding whether two programs are equivalent(EQTM) is equivalent to ATM (the halting problem). (I'll give the series of proofs if anyone requests it.)

      This means that there is no algorithmic way to transform recursive functions into iterative ones, and any substitution must be based upon matching of patterns pre-coded into the compiler.

      --
      NOTICE: This notice will appear at the bottom of all my slashdot posts.
    5. Re:you have no idea what you're talking about by boloni · · Score: 1

      The undecidability if two random programs are equivalent it does not mean that there is no algorithmic way to do the transformation. It would mean that ANY transformation is impossible, which is, of course silly.

      You can have operators which maintain the equivalence of the program, you can have series of that operators etc. For any program you can generate a lot of equivalent programs (which is what all the optimizers do).

      But I think that this overwhelming effort to get rid of the stack is a bit misdirected. At the big picture level the question is how big the stack will be, more exactly what is the spatial complexity of the problem. And now there, indeed you have some hard limits, which depend on the problem, not on your algorithm.

    6. Re:you have no idea what you're talking about by Anonymous Coward · · Score: 0

      Deciding whether two programs are equivalent(EQTM) is equivalent to ATM (the halting problem). (I'll give the series of proofs if anyone requests it.)

      This means that there is no algorithmic way to transform recursive functions into iterative ones..


      No, it doesn't!! Just because you can't tell, in general, if two programs are equivalent doesn't mean you can't transform a program to an equivalent program. Optimizing compilers do that every day, and noone had to die for it.

    7. Re:you have no idea what you're talking about by gr8_phk · · Score: 1
      "For any algorithm to determine whether or not a recursion has a simple degeneration to an iterative formula requires solving arbitrarily complex math problems."

      Yes, but this particular recursion does not require solving an arbitrarily complex math problem. I don't know how smart JAVA is about this, but if they even tried to implement that type of optimization this problem should be solved by it.

      To avoid these arguments a good benchmark will avoid trivial problems like this, as it is not representative of real world code.

      Is this problem using tail recursion? I'm not up on the exact definition. If so, it's a common (required?) optimization in the LISP world (which I am not a member of).

    8. Re:you have no idea what you're talking about by timeOday · · Score: 1
      Well, I suggest you read the other two replies to your last post, because they are correct as to transformations (even if they don't have karma bonus).

      Your other assertion here is that a recursive algorithm rewritten iteratively is still recursive if you don't do anything more complicated than maintain the state with a stack. Well this is not true. A function that does not invoke itself is not recursive, period. In fact just by looking at some (non-recursive) function that uses a stack, and judging that it could obviously be rewritten as recursion, you are finding an equivalance between them, which according to you is impossible.

    9. Re:you have no idea what you're talking about by Deliberate_Bastard · · Score: 1

      The undecidability if two random programs are equivalent it does not mean that there is no algorithmic way to do the transformation. It would mean that ANY transformation is impossible, which is, of course silly.

      No. The key word here is "algorithmic". If we use artificial intelligence (i.e. heuristic search) techniques, we can transform a program to an equivalent one most of the time.

      This is essentially what human programmers are doing when they rewrite code.

      However, we lose something here; we cannot guarantee equivalence if we do it this way, which is why it is inappropriate for compilers. You wouldn't want a compiler which could make mistakes. Debugging your own code is difficult enough.

      It is important to understand just what we mean when we say a problem is "undecideable". It doesn't mean individual instances of the problem cannot be solved. It means that there is no algorithm for solving the problem.

      So we cannot insert code into a compiler which can remove recursive functions and replace them with iterative ones. However, we *can* "pre-solve" individual patterns of recursive functions, program the compiler to recognize these patterns, and to replace them with the iterative pattern we code in for it.

      I wouldn't charaterize this as a very good idea, however. Most of these replacements involve dynamic programming, which is something any well-trained programmer should be familiar with anyway. It's dangerous to egregiously substitute a tool for a skill.

      --
      NOTICE: This notice will appear at the bottom of all my slashdot posts.
    10. Re:you have no idea what you're talking about by Deliberate_Bastard · · Score: 2, Insightful

      Your other assertion here is that a recursive algorithm rewritten iteratively is still recursive if you don't do anything more complicated than maintain the state with a stack. Well this is not true. A function that does not invoke itself is not recursive, period.

      Depends how you define recursion. The prescence of a stack which maintains states means that the function *is* invoking itself. It's just doing so in the same frame on the main stack.

      Externalizing the stack *is* more effecient. But it is still, in any meaningful sense of the term, recursive.

      In fact just by looking at some (non-recursive) function that uses a stack, and judging that it could obviously be rewritten as recursion, you are finding an equivalance between them, which according to you is impossible.

      You have misunderstood the meaning of the term "undecideable". Please see my other reply for the details of how this works.

      --
      NOTICE: This notice will appear at the bottom of all my slashdot posts.
    11. Re:you have no idea what you're talking about by angel'o'sphere · · Score: 1


      I didn't say its the definition of the problem. But you clearly don't understand how this definition applies to the real world. For any algorithm to determine whether or not a recursion has a simple degeneration to an iterative formula requires solving arbitrarily complex math problems.


      No it hasn't. Autop0n was right. Every recursive method can automaticaly be rewritten in a set of nested loops.

      You learn that usually in the third semester at a university in the CS course .... if don't learn it in school ... or figure it yourself.

      angel'o'sphere

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    12. Re:you have no idea what you're talking about by angel'o'sphere · · Score: 1

      Transformation has not really much to do with Deciding whether two programs are equivalent(EQTM).

      The algorithmic way may be difficult, because you have to transform parameter modifications from call to call into (loop?) variable modifications, sometimes you probably have to use indeed a helper stack.

      Nevertheless its possible to automate that transformation.

      Note: in case your original program would not halt on a given input, your transformed one would neither ... this topic is not touched at all.

      angel'o'sphere

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    13. Re:you have no idea what you're talking about by Jonner · · Score: 1
      That it's possible to convert looping programs into recursive programs is trivially true, because recursive functions alone are Turing complete.

      Indeed, any Scheme programmer knows this, since it is one of the foundation principles of the language. Unlike almost all other languages, Scheme has no primitive looping syntax. All looping is done with recursion and implementations must perform tail-call elimination.

      Unfortunately, the grandparent wasn't talking about implementing looping as recursion, but vice-versa:
      No, the compiler cannot guarantee the ability to transform a recursive solution to a non-recursive one.
    14. Re:you have no idea what you're talking about by hding · · Score: 1


      All looping is done with recursion


      Not so, is it? Scheme has 'do', though hardcore Schemers aren't apt to use it much.

    15. Re:you have no idea what you're talking about by fatphil · · Score: 1

      "a Turing machine, which has no concept of a 'stack'"

      Total nonsense.

      A turing machine has two stacks:
      - the tape to the left of the current position
      - the tape to the right of the current position

      """
      just compile any recursive code in any language to MIPS or some other RISC instruction set without push/pop and call functions like those found on X86 chips. You don't "call" functions directly, you just move around in memory and jump all over the place,
      """

      Total nonsense.

      Why has my Alpha have JSR (jump to subroutine) and RET (return from subroutine) instructions?

      Why does MIPS (_your_ example), PPC/POWER and TI's C80MP have JAL (jump and link) or BL/BLR (branch and link, branch to link register) instructions? It's just a call stack with extra overhead if you want to go more than 1 deep. (and less overhead if you only go 1 deep. It's therefore only useful for leaf-nodes, at which point function inlining is often a better option.)

      FP.

      --
      Also FatPhil on SoylentNews, id 863
    16. Re:you have no idea what you're talking about by Deliberate_Bastard · · Score: 1

      Transformation has not really much to do with Deciding whether two programs are equivalent(EQTM).

      It has everything to do with it. Two TMs (or programs, or subroutines) which produce the same result for every input are equivalent. Two which don't, aren't.

      A compiler may only replace code sequences with equivalent ones. It cannot make this decision itself, because to do so, it would have to solve EQTM.

      So just what the hell is it that compilers do?

      They match and replace patterns. But the equivalence of these pattern pairs (replace-x-with-y) was predetermined by a human being. And human beings do this heuristically, rather than algorithmically, which is why we can do it at all.

      Nevertheless its possible to automate that transformation.

      "Can automate" != "algorithmic"

      Note: in case your original program would not halt on a given input, your transformed one would neither ... this topic is not touched at all.

      Please go back and read carefully what I said about one problem reducing to the other. If you are still confused after that, I recommend Michael Sipser's excellent (and mercifully concise) textbook "Introduction to the Theory of Computation."

      --
      NOTICE: This notice will appear at the bottom of all my slashdot posts.
    17. Re:you have no idea what you're talking about by maximilln · · Score: 1

      This means that there is no algorithmic way to transform recursive functions into iterative ones, and any substitution must be based upon matching of patterns pre-coded into the compiler

      I agree. I came across a similar concept in a Number Theory course. Consider a set of numbers where the member n is derived from a function of n-1. In many cases it is desirable to have an absolute equation where F(n) directly computes any member without knowing the member before it. We found that there were useful techniques in converting one system to the other but there was no tried and true stepwise method which could reliably generate an absolute function from a sequential function.

      And then there's always the set of prime numbers which doesn't have any currently describable function, sequential, absolute, or otherwise.

      --
      +++ATHZ 99:5:80
  323. Re:Agree, Java can be great with a little profilin by Anonymous Coward · · Score: 0

    Any advice for profiling in java? I write some apps, but have rarely done profiling, and don't really know where to start. Suggestions?

  324. Given infinite time C/C++ is faster by Ambassador+Kosh · · Score: 1

    Given enough time a C/C++ application will end up beating one in java/python/perl/c# etc but lets be honest in the real world there is not infinite time. It takes a LOT of work to make a fast C/C++ application that has had the memory leaks removed, bounds checked where they need to be etc. In the higher level languages you can implement a good enough solution that is fast enough quickly and it is simpler to debug and fix them.

    I have seen a number of apps redone in java/python etc that have ended up a good deal faster then the c/c++ versions where. It also usually takes a month to do what it took 10-12 months to do in the c/c++ version.

    For example in python you have dictionaries and because they are so simple to use people tend to use them as a base data structure all over the place and in python dictionaries are probably the most heavily optimized piece of code it has. So the most natural way to make a hashtable is just built in which tends to be a good deal harder in various lower level languages.

    Also it is often easier to make a program written in a higher level language faster then it started out with basic profiling since the code is shorter and simpler to read. Overall from what I have seen programs in higher level langauges tend to be optimized more if it is important since it takes far less time to code them and the optimization is usually simpler to see and write.

    --
    Computer modeling for biotech drug manufacturing is HARD! :)
  325. Languaje choice IS a big factor! by Anonymous Coward · · Score: 0

    Evidence: programming in C is MUCH faster than assembly.. I don't care how much upfront design you use. Not only is the level of abstraction higher, but the tools are better.

    I'd argue that Java is at a higher level of abstraction than C++ and has less distracting features (which waste a project's) time.

    I speak from experience: at company X we developed a project with a not so formal programming methodology.. results: slow dev in C++ (we were all highly experienced with the language too)

    at the same company we switched to Java. Soon we developed an app using the same not so formal methodology and had much better results in much less time. We thought performance would be a problem but our experience was otherwise. That was at JDK 1.2. None of us knew any Java either at the beginning of the project but learned as we went.

    Methology was not a factor.

    I'd say my experience and that of some of the other hard core ex-C++ developers on this forum is enough hard fact. Opponents give no concrete examples.

    Even before this I had experience in the Smalltalk world. And participated in a Smalltalk dev project and was amazed at their 6 month product cycle. In C/C++ it was always a year long cycle.

    Don't underestimate the power of the tools you are working with. (Java has some of the best dev tools too like IntelliJ IDEA)

    Finally, you may say that Java cheats because of APIs.. But that is, in my opinion, the point. Java has a zillion APIs.. C++ doesn't. C++ even after all these years doesn't have the API support.. why not? Culture??

    Whatever it is.. the choice of your platform DOES matter. Java usually wins in devtime/debug time/ maintenance time.. the metric that REALLY matters to companies. Execution time is usually poor design... in any language.

    1. Re:Languaje choice IS a big factor! by gnuLNX · · Score: 1

      "Opponents give no concrete examples."

      And you have given some concrete example?

      you say C++ has no api's...STL? Personally I don't want all the extra garbage that comes with Java...don't get me wrong I like the elegance of the language, but for what I do...scientific programming. Java just ain't the languace of choice..hell some of my co-workers give me hell for using a language as slow as C++...(fortran fans they are!)

      My only point is that C++ and Java are both very good language in the right circumstance...you want to write business apps...use Java...however the finacial world still considers C+ the end all be all.

      However ifyou want to write fast code...with inline assembly in those tight loops...use C/C++. Period.

      --
      what?
  326. The plural of "anecdote" is not "data." by Anonymous Coward · · Score: 0

    Why is it you people don't understand that one test, on one platform doing one thing cannot be extrapolated to an infinite population of potentail applications. Count to 10,000 indeed.

  327. Re:Thanks. Article is a troll. by Anonymous Coward · · Score: 0
    Oh, look. Troll. Troll, troll, troll. Pathetic worthless zealot troll ranting away his pointless vacuous stupid foam for everyone to laugh at.

    Stick to your journal twit. No one will bother you there, and no one will read it, so no one will feel the need to mod you down. You can escape the "M$ astroturfers" in the employ of Bill Gates, living in Bangalore. Really.

    Tut, tut.

  328. Turing completeness does not extend to I/O by tepples · · Score: 1

    Turing machines have no real-time input nor any output except one bit representing a function of a string. Thus, the strictest sense of Turing completeness doesn't apply to operating system kernels, which manage all of a computer's input and output.

  329. Latest ARM CPUs by Anonymous Coward · · Score: 0

    There are now some ARM CPU cores you can license that support 3 instruction sets: ARM, Thumb, and Java bytecode. Now, some of the bytecodes are implemented partially or fully in software by causing interrupts.

    However:
    1) You either need to write a bytecode-to-bytecode JIT, or you lose the advantages of runtime profiling and code generation (no de-virtualization, etc.).

    2) A significant portion of the speed issues with java come from language features that still need to be paid for in your hardware implementation (gc, bounds checking, all methods virtual, encouraging excessive allocation and freeing, etc.)

    3) Almost all Java compilers use very little optimization of bytecode, because they expect the code to be optimized again at runtime. Some compile-time optimizations actually have the effect of obfuscating bytecode so that JITs become less able to optimize (without wasting lots of time with more extensive analysis). You could write your own javac optimized for your particular implementation, but while you're writing a compiler, you could just as easily target it to native code on a CPU architecture that has many orders of magnitude more development funding going into it than your little research chip.

    4) Hardware bugs are less fixable than software bugs. Commercial Off The Shelf (COTS) hardware is a huge advantage here. Are you really going to make a hardware Java chip that is going to get close enough in raw native speed to an Opteron or G5 that the JIT needed by the COTS chip is going to tip the scales in your favor?

  330. K5 doesn't allow new user sign-ups by tepples · · Score: 2, Informative

    At last count, Kuro5hin was closed to new users. Therefore, K5 is not a general purpose discussion site. New users have mostly gone to K6 instead.

  331. ABI compatibility by tepples · · Score: 2, Interesting

    It's a benchmark. We're benchmarking performance.

    Correctness comes before performance. Failing to link at all by no means produces good performance because a test of performance on incorrect code is an invalid test. Using one C++ compiler to compile your system libraries and another C++ compiler to compile your applications will often result in either failure to link or incorrect code because of subtle ABI (application binary interface) differences among C++ implementations.

    On the other hand, the Java platform ABI is well-defined for several years now.

    And would you grant that the benchmark is a valid test of Sun's implementation of the Java language vs. the G++ implementation of the C++ language?

  332. Re:Can I have an infinite budget to write the code by Calroth · · Score: 1

    There are thousands of differences between C# and C, between C# and Perl, or C# and assembly language.

    If you can only come up with a few dozen differences between C# and Java, then relatively speaking, they're almost exactly the same.

  333. Let me try! Let me try! by Anonymous Coward · · Score: 0

    I wrote two programs, one in java and one in c++ that creates 10000 Hello(String/char *) objects. They just print s to stdout when created.

    java $ time java Driver > /dev/null

    real 0m0.204s
    user 0m0.180s
    sys 0m0.016s
    java $ time java -server Driver > /dev/null

    real 0m1.191s
    user 0m0.476s
    sys 0m0.028s
    java $ time java -server Driver > /dev/null

    real 0m0.510s
    user 0m0.475s
    sys 0m0.024s
    java $ time java -server Driver > /dev/null

    real 0m0.535s
    user 0m0.483s
    sys 0m0.014s

    Now for C++:

    c++ $ g++ -O3 driver.cpp Hello.cpp
    c++ $ time ./a.out > /dev/null

    real 0m0.015s
    user 0m0.005s
    sys 0m0.001s

    The constructors where System.out.println(s); and printf(s); where s was "hi".

    int main() {
    Hello *h = 0;
    for (int i = 0; i < 10000; i++) {
    h = new Hello("hi");
    delete h;
    }

    return 0;
    }

    public static void main(String[] args) {
    Hello h = null;
    for (int i = 0; i < 10000; i++) {
    h = new Hello("hi");
    }
    } // end of main()

    Now i realize, i didn't prove crap there. I mean, there are so many differences its like I didn't even put any thought into it. In other words, this test is just like the article.

  334. Study Already Performed by Joeseph Kaylor by Dozix007 · · Score: 1

    A study testing Java to C in speed has already been performed 6 months ago (predating this study). Please check http://web.ics.purdue.edu/~jpkaylor/trig.html for the original information.

  335. outdated claim by TheLittleJetson · · Score: 1

    i too, am sick of hearing about how slow java is. i think this claim had a lot more validity back in the day ('98 or so) but now it's just echoed amongst the idiots. one thing they've beaten into us in computer science courses, is that optimization is really only needed in a few critical areas, and the rest of the program wont depend that much on performance.

    with today's absurdly fast computers, just-in-time compiling and runtime optimizations, semi-native environments (OSX's java, GCJ, JNI, or projects combining multiple languages) -- why must this issue constantly be touted every time java is mentioned?

  336. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    If I was developing a large (and perhaps distributed) application

    What?!?!?!?!!!!!!

    You are the exact person why I made the comment above I create and administer clusters. And if you compare distibuted applications everything sucks except for tuned assembly (with C on top) or possibly fortran. I can't believe you said Java would be faster when distibuted.

    That was just terrible...

    My $0.02

  337. Amen by Anonymous Coward · · Score: 0

    Thank you! Someone had to say it!

    (Glad it was you, because I wouldn't have used those words, I would have covered the ears of the children ;o)

    My $0.02

  338. ObjC in GCC; Openstep API in GNUstep by tepples · · Score: 1

    As a downside though, I'm not sure how well supported it is on non-OS-X platforms.

    The GCC source code distribution includes an Objective-C front end. Are these platforms enough for you? Sure, you don't get the Cocoa/Openstep libraries everywhere, but the GNUstep team is working on that.

  339. Re:Really? Try this one. by gregbaker · · Score: 1
    I'd like to see a C++ implementation of the Halting Problem that's faster than a Java implementation, please, thank you.
    I hate to be pedantic*, but the halting problem is a problem, not an algorithm. If you hand me a correct algorithm for the halting problem, I'm sure it could be coded in C++ so it ran faster than in Java. Of course, that has nothing to do with the languages, I'm also sure 0 would be equal to 1.

    (That's not actually true. I like being pedantic. I don't like having to do it in public.)

  340. Re:Can I have an infinite budget to write the code by swillden · · Score: 1

    And Visual Basic is even easier to use for creating simplistic GUIs, but that doesn't mean that it is better.

    Ugh, no. VB's widgets are horrible. Full of bizarre and illogical interfaces and behaviors. The only thing VB has going for it is a nice GUI builder.

    Qt's lack of basic design patterns

    Examples? Which patterns do you think ought to be implemented in the framework which are not?

    notification mechanism

    Qt's notification mechanisms (signals and slots) are excellent. Very flexible, powerful and simple to use.

    relatively poorly designed widgets and lack of flexibility makes implementing anything that goes out of the ordinary a nightmare

    Sorry, but I can't agree with these generic complaints. You'll have to be more specific. I've found that Qt's widget set provides a great deal of functionality, and as far as the design goes, I usually find that I can use them without referring to the documentation beyond a glance at the method names. That's a sign of very good design. The widgets are also easy to extend, and having the source means that there is ultimately nothing you can't do.

    I have used lots of different GUI toolkits over the years, and Qt is one of the best ones I've seen. In fact, it's at least as good as everything I've used, with the sole exception of the NeXT toolkit.

    Maybe a good place for you to start would be to point to a GUI toolkit that you think is better than Qt. MFC?

    --
    Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  341. Re:You are eliminated the whole point of profiling by KnacTheMife · · Score: 0

    The study supposedly was not designed to highlight the benefit of Java but to benchmark for comparison the two languages. To do this accurately, compilation advantages should be leveled out. For an analogy, if you wanted to accurately compare the skill of two race-car drivers, they should be tested in identical environments, same track, car, weather conditions etc.

    --
    -- "Someone's gotta go back for a shit-load of dimes."
  342. Re:Can I have an infinite budget to write the code by swillden · · Score: 1

    Qt's X11 GPL version is free. A commercial license is not.

    Nope. But it's quite reasonably-priced, as professional development tools go. Well worth the price. A much better value than the Rational tools, for example.

    --
    Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  343. How to set the native look & feel by node159 · · Score: 1

    Try: // Use OS L&F
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());
    } catch (Exception e) {
    if (DEBUG) {
    System.err.println("Unable to set Look & Feel");
    }
    }

    I mean its still as ugly as hell but now it looks more like the native OS, just don't expect it too like the version your using, more probably a few revisions back :/

    --
    GPLv2: I want my rights, I want my phone call! DRM: What use is a phone call, if you are unable to speak?
  344. Re:Can I have an infinite budget to write the code by kaffiene · · Score: 1

    Pascal and C are about as similar as are C# and Java. In many regards, they are the same class of language, but there are still features that may be must haves or must-not-haves in deciding between them.

  345. Non-free(beer) compiler imposes a speed handicap by tepples · · Score: 1

    Intel C Compiler, with inter-procedural optimizations enabled, produces code that's almost always 20->30% faster than g++.

    Remember that ICC's speed is hampered by the time it takes each user to flip enough burgers to earn money to afford a license for ICC. This will be true of any compiler not available under a gratis license.

    "Well then use the Linux version, which is gratis for non-commercial use!" You refer to the "Non-Commercial Unsupported Version", which exists for GNU/Linux but not for Microsoft Windows. Virtually all store-bought computers contain Microsoft Windows, and many contain hardware that happens to be unsupported under GNU/Linux. Replacing this hardware with new hardware also requires flipping burgers, which takes time.

  346. at risk of sounding like microsoft... by smash · · Score: 1
    ... compiler technology, combined with ever increasing cpu speed is gradually making optimisation a non-issue for most situations.

    Processing power is cheaper than programmer time, and increases at an exponential rate.

    As this trend continues, requirement for optimised code will only lessen. If you spend a month trying to get a 10% speed increase by optimisation, you're barely keeping up with hardware advances...

    Sure, there's games, etc that need quick code, but even then, the old axiom "90% of the time is spent in 10% of the code" applies.

    Write the 90% in a high level language of your choice, and optimise that remaining 10% *if required*. That 10% is largely covered by libraries such as directX, openGL, etc... even game developers do this these days to an extent - no longer are games written in 100% assembler. They've become too complex for that.... and are now mostly C with hotspots optimised as required.

    At the end of the day, pick a language that is easy to code/debug, and suited to the particular task you are trying to accomplish.

    smash.

    --
    I run: Windows, OS X, Linux, FreeBSD. Just because you have a hammer, doesn't mean everything is a nail.
    1. Re:at risk of sounding like microsoft... by nevets · · Score: 2

      In a lot of cases, you are right. But some of us (me included) work on military or other complex systems that getting 10 percent faster output would be great. I find that there is a lot of effort going on to put as much as posible on the smallest amount of hardware. The system may be fast, but the work load is going up, since to make things lighter, you run five apps that use to run on five different machines, on a single unit. One project switched to Java and is now suffering from performance issues. Now the code needs to be redesigned to get the required output.

      Speed will always matter, until we solve those nasty NP problems ;-)

      --
      Steven Rostedt
      -- Nevermind
  347. Re:C++ has some shortcomings. by KnacTheMife · · Score: 0

    "shoots the compiler into the foot" hmmm...a foot cannon...interesting :)

    --
    -- "Someone's gotta go back for a shit-load of dimes."
  348. Re:Caught up with the speed, but still the ugliest by SlashdotKeefey · · Score: 1

    I agree. Although I have never programmed in Assembler, I can understand it when the need to debug through it arises. However, more importantly to the needs of a typical business, I would suggest investing the time in improving the current programming skills of the developers (whether it be Java or C++) and get them to be able to code effectively, rather than shoe-horn them down the route of an 'elite' language such as assembler, just because, at the end, that coder will be somehow deemed more worhtwhile.

    It matters little in the majority of applications what language they use as long as it gets the job done within acceptable metrics. Most of the time, it's not the code that is at fault, but the usage of the DB (in my experience).

    My personal preference, knowing both Java and C++, is C++. Yeah, C++ is a monolith of a language, and the mass of different ways to do the same thing can be a detrement (especially to novice coders), but when you learn the better ways of achieving particular things is becomes a joy to use, while still being maintainable. However, I can see the advantages of using Java, and it's basically a case of using the tools that match the needs of the organisation.

  349. So you want to ABX different computers, huh? by tepples · · Score: 1

    To see what I mean, head down to your local computer store and fire up your favorite application on a 2.4 GHz and a 3.1GHz machine. [description of blind testing method follows]

    Given an emulator's numerical frame rate indicator, and given that an emulator showing a complex scene on one display might dip below the display's refresh rate on the slower machine, causing visible jerkiness, I could probably ABX the machines at 18/20 or better.

    1. Re:So you want to ABX different computers, huh? by Anonymous Coward · · Score: 0
      ...[description of blind testing method follows]

      Given an emulator's numerical frame rate indicator...

      You can't use a numerical framerate indicator. That's not a blind test. ;)
    2. Re:So you want to ABX different computers, huh? by Anonymous Coward · · Score: 0

      Turn off the FPS display, and the test becomes valid, right?

  350. FAIL YOUR STUDENT by EventHorizon · · Score: 2, Funny

    And tell him to check for buffer overruns next time (num > max).

    On the plus side: after he flunks out, he can go write RPC code at Microsoft.

    Or, perhaps, a cell phone bluetooth stack.

    [Ducks And Covers]

  351. PCs are LBAs, and Halting for LBAs is solved by tepples · · Score: 2, Interesting

    If you hand me a correct algorithm for the halting problem, I'm sure it could be coded in C++ so it ran faster than in Java.

    A Turing machine modified to have a limited-length tape is called a Linear Bounded Automaton (LBA). A PC is equivalent not to a Turing machine but to an LBA. There does exist a correct algorithm for the halting problem when applied to LBAs: emulate two copies in a tortoise-hare configuration and look for loops in their state.

  352. Built-in C? by tepples · · Score: 1

    The Java language is also a shorthand for bytecodes, but those bytecodes are helpless without a virtual machine.

    The C language is also a shorthand for opcodes, but those opcodes are helpless without a virtual machine.

    Modern x86 processors treat opcodes as bytecodes for a virtual machine, translating them into something that the processor's more RISC-ish backend can use. Some even reorder the operations. Just look at the microarchitecture of any Pentium 4 or Athlon processor; the P4 even has a "trace cache" to store recompiled micro-ops. Transmeta's processors go even deeper.

  353. Ugh by Anonymous Coward · · Score: 0

    You assholes really are out of control. I hope you are pleased with yourselves, but it does not matter, Microsoft is doomed. A man can only disgrace himself and you morons have done a good job of it.

  354. jEdit vs. Emacs by mr_data_esq · · Score: 1

    I used to use Emacs a lot. I use jEdit mainly now, because I really like it; it helps me work faster. But I definitely don't use it because it's fast. It's not. jEdit isn't as slow as Micro$oft Word (substitute 'tu' for 'wo' to see my opinion of that "program"), but it's pretty darn slow. It's so slow that, although I liked the program when I first tried it, it was just too slow, on every platform I tried it on (Linux, Windows, OS X). I've got past that now, because slow as it is, it helps me work faster.

    Know why jEdit is slow? 'Cause it's written in Java. Every Java app I've ever used is dog-slow, especially compared to C++ apps. C++ was designed to be fast; and when used properly, it is. Java was designed to be portable; after several years, false starts, marketing hype and outright sabotage, it pretty much is. But it wasn't designed to be fast. That's not the point of it. It's designed to be portable and easy to program (and to make lots of money for Sun, somehow, but that's another topic).

    This guy may have thrown together a benchmark, but I've got a better one: experience. Wake me up when jEdit runs almost as fast as Emacs on the same machine; then I'll start to believe this stuff.

    And yes, I know Emacs isn't written in C++; it's written partly in C, partly in Lisp. So most of it's interpreted. (Some claim that Emacs stands for "eighty megs and continuously swapping".) So I think this is a way more than fair comparison.

  355. GNU STL not commercial quality by LonelyKindGuy · · Score: 1

    If you're using gcc 3.3 for this comparison, then you're truly picking a lame implementation of the STL. No wonder Java is even _close_ to C++.

    Try using something with a more optimized STL, like the free STLport from STLport.org.

    1. Re:GNU STL not commercial quality by cimetmc · · Score: 1

      You should also note that lately, the GCC developers have put more effort in speeding up libstdc++. You might want to check the GCC 3.4 release notes and the Proceedings of the GCC summit in that context.

  356. Apples? Oranges? How *should* we comapre them? by Trinition · · Score: 1

    I think everyone has pointed out in many ways why these tests and comparisons were flawed. Much of it boils down to deciding what exactly "C++" is and what exactly "Java" is. IN fact, I don't think either of those terms is even specific enough to build benchmarks around.

    With C++, there is the language syntax, the standard libraries, which compiler you use, which optimizaitons you chose, etc. Within Java, there is the version, the libaries, the VM vendor, the VM optimizations, etc. And then you have to consider that some tests might perform better in one of the languages on one platform but the reverse on another -- where the platform might be OS, hardware, or both.

    And then how you measure "performance"? The first execution? Subsequent executions? If you ask a business manager, they might include time-to-develop as a performance measurement. OR howw about time spent mediating the religious war started in an IT department over which language to use???

  357. Re:Really? Try this one. by Anonymous Coward · · Score: 0

    The Halting problem is just a decision problem - it is NOT an algorithm.

    "An algorithm is an understandable and finite set of instructions for accomplishing some task which, given a defined set of inputs, will result in some recognisable end-state"

  358. Constant-space version by tepples · · Score: 1

    It can be done in constant space, saving a malloc() call. Does this version run any faster?

    #include <iostream>
    #include <cstdlib>

    using namespace std;

    unsigned long fib(unsigned long n) {
    unsigned long i;
    unsigned int fibnm1 = 1, fibn = 1;

    if (n < 2) return (1);

    for (i = 2; i <= n; i++) {
    unsigned int fib_tmp = fibn + fibnm1;
    fibnm1 = fibn;
    fibn = fib_tmp;
    }

    return(fibn);
    }

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

    cout << fib(n) << endl;
    return(0);
    }
    1. Re:Constant-space version by Xugumad · · Score: 1

      Yup - probably because the processor can cache it better (your implementation may even run entirely in registers for the main loop)!

      [jrn@bowmore slashdot]$ time ./fibo_flat 20000000
      1933176546

      real 0m0.320s
      user 0m0.270s
      sys 0m0.050s
      [jrn@bowmore slashdot]$ time ./fibo_const 20000000
      1933176546

      real 0m0.041s
      user 0m0.040s
      sys 0m0.000s
  359. Re:Thanks. Article is a troll. by Anonymous Coward · · Score: 0
    The article must have been a troll. It recommends non-free software

    Imagine that. How evil of him, and how self-defeating of Slashdot to post it.

    Now, go back to your meds.

  360. Java is written in C, not C++. by Ayanami+Rei · · Score: 1

    Just a little FYI... also, so is ECMA-script, and the CIL, IIRC.

    --
    THIS THING CAN TURN ON A DIME, MACROSSZERO STYLE ALSO FUCK BETA, ~NYORON
  361. Re:Really? Try this one. by cardshark2001 · · Score: 2, Insightful
    I'd like to see a C++ implementation of the Halting Problem

    Eh.... so for your counter example you choose a problem that is unsolvable in any language?

    Did you just read about that in your computer science class or something? How does that relate to the question at hand? For any java implementation, of any algorithm, I (or someone else) can write a c++ implementation that is faster. Does this mean that I can solve problems in c++ that are unsolvable? Ummm.... no.

    This is a common logical fallacy. Its Latin name is "Non-Sequitur". You'll probably get to that next year when you study logic.

    --
    WWJD? JWRTFA!
  362. Congratulations by GunFodder · · Score: 1

    You just proved that the results of a trivial test are trivial.

  363. clues that this is one big troll by twitter · · Score: 1
    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.

    Clues in order:

    1. The page was replaced by a bunch of "I hate Slashdot" bullshit. Doug should really be complaining that his hoster was hosing him for a a foreseeable event. Well, maybe he thought no one would be interested in flamebait.
    2. The title. "The Java is Faster than C++ and C++ Sucks, Unbiased Benchmark" Sucks? The only thing that ever sucks in a computer language is when the language changes and breaks your code.
    3. The pile on of trolls here repeating the same BS as you find on the "quit slashdot" page. Mostly bull about how Slashdot's editors and readers can not be trusted for technical information.

    The article is a troll. It was designed to FUD Slashdot. Well done, assholes. Between this and Google bombing, it will be harder for some of us to learn. Whatever Microsoft is paying you for this stuff is too much. This is as transparent as the Apple Switcher.

    Interestingly enough, the trolls are also wrong. Now that the article is visible, people are picking it to pieces. I doubt people are going to walk away with the wrong impression.

    In any case, I could care less. Java is non free. As nifty as it is, I can do the same things with free code. Even if java was faster at this and that, the fact that it's not free makes it a dead end. Sun's not an evil company today, but they can become one tomorrow. Why would I put my work in their hands when I can own it myself?

    --

    Friends don't help friends install M$ junk.

    1. Re:clues that this is one big troll by Anonymous Coward · · Score: 0
      Moderators: Please note that "twitter" is a known fanatical psycophant whose obnoxious offtopic rants are legend here on Slashdot. It doesn't matter what the topic is, he'll find a way to scrape in some pointless Microsoft bashing. While nobody expects us to love Microsoft in any way, his particularly tepid style of calling anyone he replies to "troll" or "liar" or "fanboy" because he happens to disagree with whatever they're saying is well documented and should not be rewarded. If anything, twitter is the type of person that should not be part of the open source/free software community. He is an anathema to all that is good about free software.

      I'm posting this so that you (the moderator) have some context to consider twitter and not mod him up whenever he posts his filler preformatted rants about installing Knoppix or whatever that unfortunately get him karma every single time and allow him to continue posting his trademark toxic crap (read on) day in and day out. You may consider this a troll - I consider it community service. And I ain't kidding.

      If you're a /. subscriber, I invite you to look through some of his posting history. I guarantee that you'll be hard pressed to find someone that is more "out there" than twitter. You'll also probably notice he's got quite an AC following. Don't just read his posts, make sure you go through the replies.

      To get an idea of what I'm talking about, check this post out. I mean, this is an article about email disclaimers, right? The parent of the post is complaining about the ads in the linked page and so on, and twitter actually goes off on a rant to blame it on Microsoft and recommend Lynx. WTF?

      Here's another. In this post twitter not only calls the OP a troll but attempts to "tell it like it is" while making some vague argument about "GNU". Yes, if you're confused, you're not alone. The reply (modded +4) proceeds to simply destroy his bogus argument. You will notice he did not reply. This is what some people call "drive-by advocacy". A sort of I'll just leave you with my thoughts here and move on to the next flamebait kind of deal. In fact, he almost never replies because he knows that his fanatical arguments simply do not hold up to any sort of discussion. It's not that he's chosen the wrong cause - he's just going at it in a completely wrong way.

      More? Just read though this post and the subsequent replies. I guess this stands on its own. Or these two. Or this one.

      More? Bad spelling in astounding conspiracy theories, more offtopic FUD and uninformed "I'm right, look at me" rants, promptly proven wrong. Worse even, twitter wants to be RMS, apparently (that first one is a winner). I mean, really. You think?

      FUD,

    2. Re:clues that this is one big troll by Anonymous Coward · · Score: 0
      "I can do the same things with free code"

      twitter:

      Strange as this "free code" term of yours might be, please post a link to some code you have written. Anything. Let's see some of your work before you can offer us your opinion on this topic and "free code".

      You see, after looking at your posts I get the impression that you've never written a single line of meaningful code in your entire life.

      So give us a link. Some PHP or Perl or JSP site, or some project you've contributed to, or your personal project page or some commit log with your name. Some article about a technical topic. A blog. Anything. Anything at all. Most people in Slashdot have something like that.

      Thanks!

  364. Am I missing something here? by ad0le · · Score: 1

    Ok, first off, I write software for a living. So my main issues are deadlines, productivity and total cost of production. And guess what's gonna win over, when given the choice between picking a compiler that's 1.2 ms faster in "certain" "controlled" situations or having a nice elegant language that scale properly and is easy to maintain.

    Imagine trying to tell a customer, well I can give you the app in 3 days for 10K that will run fine on you new $300 Celeron's or you can have it in 3 months for 100K and it'll implement (insert geeky mathematical function) in a more efficient manner.

    I get the feeling that you guys bitching about the very minimal difference between these languages, are either A) Writing only low-level libraries. B) Regurgitating whatever tech website you read about earlier today. Or C) Have no "industry" experience and have nothing better to do than try to skew opinions one way or another.

    Who fucking cares? Tell ya what, I'll use one of the highest-level language out there (Delphi or C#). You use your Java or C++ and we both start on an intensely complex and graphical database application on the same day. Not only am I going to be done days maybe even weeks before you, but the consumer is not going to know that your application runs slightly faster, more efficient, or even 5x better.

    Just my 2 cents.

    --
    My mother never saw the irony in calling me a son-of-a-bitch.
    1. Re:Am I missing something here? by MS_is_the_best · · Score: 1

      Not all coders write database apps. (Yep, databases are slow, this kind of optimisation is not so useful).

      But there are a lot of us who write 'scientific' codes. For example for modeling fluids, calculating acoustics, analyzing space-images, etc. etc. This kind of programs typically take days to run, so every speed does matter!

      And there is realtime code. For example for coding audio. Even changing an underlying transform to a slightly different program can make ogg work on our ipod for example.

      But to come back on the scientific apps: physicists are often not such good programmers, being able to use Java would be nice, if it was just as fast as the C++ code.

    2. Re:Am I missing something here? by smash · · Score: 1
      This is a clear example of using the correct language for the job.

      Need some bit of scientific code to run fast? Pay a decent c/assembly coder.

      Need to get a prototype of the app running quickly in the meantime? Use C#/Java/etc...

      Yes, you can use a screwdriver for many things (screws, drilling holes, prying things open, hammering nails), but its not the best tool for the job.

      The same applies to programming languages...

      Java has its place...

      smash.

      --
      I run: Windows, OS X, Linux, FreeBSD. Just because you have a hammer, doesn't mean everything is a nail.
  365. Not really by vlad_petric · · Score: 1
    The only procs that treats x86 as a bytecode are perhaps Transmeta's. All other processors simply decompose complex instructions into simpler ones, without doing any post-optimization.

    You might say that that's what JVMs do. But ... you're wrong. Simply translating java bytecode into machine code doesn't get you much - i.e. you're only marginally faster than interpretation (that's a research result from IBM). What you have to do is to reconstruct the data and control flow from the bytecode, and only then do the actual compilation.

    The same is pretty much true about x86, if you want to get good performance out of it. That's mainly the reason for x86-64 and Itanium - both actually clean up the instruction set.

    --

    The Raven

  366. (erk, at least it was, never mind) by Anonymous Coward · · Score: 0
  367. Apples to Apples please by davegust · · Score: 1

    These two examples do different things. One must do a proper conversion from int to string, and the other is a simple math operation to cast from int to char.

    I think the point you were trying to make is that the C++ stream library is slower than the C file I/O library. Yes, genius, it generally is, but only by a small amount.

    You miss the point about the duality of C++ - it's both low level and high level. I can use classes when I want object oriented designs that encourage reuse and are easy to maintain, but I can still use C coding techniques when I really need extreme performance.

  368. Re:Some performance myths by Tokerat · · Score: 1


    Automatic double-optimized code +bonus language and platform portability?

    Hey, if it works, I'm down.

    --
    CAn'T CompreHend SARcaSm?
  369. Why? by magerquark.de · · Score: 1

    You write: "the more people who know about present-day Java performance, the better"

    Why do you think so?

    --
    -- Watch me working: www.magerquark.de
  370. Write a JVM in Java??? by Ytsejam-03 · · Score: 2, Insightful
    The fact that Java VMs are primarily written in C or C++ indicates that at the time they were initially written, it was believed (I think correctly) that the C or C++ at that time would be a better platform for writing JVMs than the Java of that time, and that since then it has been considered better to extend the existing code than to scrap it and do a complete rewrite in Java.

    That's all that this argument proves. Nothing more.

    What I'm saying, though, should not be interpreted as a belief that today's Java would be a better choice than today's C++ for writing a Java JVM. I don't know what the relative advantages would be today.
    Am I missing something, or did you just suggest writing a JVM in Java? Which language will you use to implement the JVM that will run your Java-implemented JVM?

    My understanding is that JVM performance has improved because they are now doing things like selecting the appropriate instruction set for the processor at runtime. This is opposed to natively complied languages which are typically compiled to support the lowest common denominator.
    1. Re:Write a JVM in Java??? by gammelby · · Score: 1
      Ytsejam-03 wrote:
      Am I missing something, or did you just suggest writing a JVM in Java?
      Somebody already took care of that Ulrik
    2. Re:Write a JVM in Java??? by nacturation · · Score: 1

      Am I missing something, or did you just suggest writing a JVM in Java? Which language will you use to implement the JVM that will run your Java-implemented JVM?

      It's called bootstrapping. For example, the GCC compiler can compile its own source code. Of course, the initial version of GCC had to be compiled with something else... similar to how the initial JVM had to be written in something else.

      --
      Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
    3. Re:Write a JVM in Java??? by ArsenneLupin · · Score: 2, Informative
      For example, the GCC compiler can compile its own source code.

      Yes, the GCC compiler. However a JVM is an interpreter.

    4. Re:Write a JVM in Java??? by elhaf · · Score: 2, Interesting

      Yes, and Java is a language. Your point? Java is turing-equivalent. According to the Church-Turing thesis, anything computable can be written in Java. Including a JVM. One does need to execute that JVM, of course, but that's true of any bootstrap operation. It is possible to compile java to native code; JIT's do it all the time. C still needs some assembly routines at startup to run, and it relies on a BIOS underneath. If you want a real mind-bender on this subject, look into Futamura projections for some fun.

      --
      Six score characters.
      Brevity being wit's soul
      I have enough space.
    5. Re:Write a JVM in Java??? by E_elven · · Score: 1

      > It is possible to compile java to native code; JIT's do it all the time.

      Well, the JVM wouldn't be written in Java then, would it?

      --
      Marxist evolution is just N generations away!
    6. Re:Write a JVM in Java??? by BayBlade · · Score: 1
      The JVM can be written in anything. You're assuming Java the language is incapable of running outside Java the machine. This is a common mistake because most Java compilers compile for Java Machines, and the mistake is even more forgivable following an article that compares a native compiler to JVM bytecode inside a Java machine.
      This is not, however, the only case.

      The bottom line is that machine code generated from any language can interpret Java and run it just in time.

      --

      The key difference between a Programmer and a Senior Programmer is that one of them is Mexican.

    7. Re:Write a JVM in Java??? by codemachine · · Score: 1

      Yes it would dumbass. Write it in Java and compile it with something like gcj. Voila, you have a JVM written in Java.

      Not that this hasn't already been done. I believe IBM's Jikes virtual machine is written in Java.

    8. Re:Write a JVM in Java??? by AKAImBatman · · Score: 1

      Yes, the GCC compiler. However a JVM is an interpreter.

      Not another one of these. *groan*

      Java is a JITted language, not an interpretted language!

      What is a JITted language you ask? It means that the JVM waits to run the compile until the application is run. Then it compiles the Java code to platform specific code. Many of the performance numbers are the JVM taking advantage of individual processor features. C++ can't do that, because you have to compile to the lowest common denominator (e.g. a 386 or Original Pentium).

    9. Re:Write a JVM in Java??? by E_elven · · Score: 1

      Well, dumbass, Java comes with a runtime. The language and the runtime form the entity known as Java. If the compiler is written in Java and then compiled to native code, then there's another compiler implemented in native code (essentially C++->native code per the VM's language), in no way distinguishable from the original compiler. So the only way to write a compiler in Java is to run the compiler in the JVM, which the GP shunned in favour of native code.

      --
      Marxist evolution is just N generations away!
    10. Re:Write a JVM in Java??? by Anonymous Coward · · Score: 0

      Java isn't an anything language. Java the language has no concept of JIT compilation. Your Java platform might use JIT compilation. It might also just use bytecode interpretation. It might compile directly to native code, too.

    11. Re:Write a JVM in Java??? by Anonymous Coward · · Score: 0

      You do realize you don't have a clue what you're talking about right?

      Although the original poster didn't need to insult people, he/she was pretty much correct. All you're really countering with is what the "Java" brand entails, which isn't the same thing the Java language that people here are talking about.

      Most people consider gjc to be a Java compiler, even if it isn't certified to use the 'Java' trademark. Most people consider Java to be a language, not a brand. Java == C#, JVM == .NET runtime, if you want comparisons. You're trying to say that you can't write a JVM in Java b/c the JVM is part of Java. But the previous sentance used Java to mean 2 different things (language vs trademark/entire Sun certified package), so the logic is faulty. There is no reason you can't write a JVM using the Java language (in fact, it has been done many times). And if it passed Sun certification, you could probably use the Java trademark as well.

      So maybe you should figure out what you're talking about before you go calling people dumbasses.

    12. Re:Write a JVM in Java??? by E_elven · · Score: 1

      Christ.

      The GGGGP said it'd be bad to write a Java compiler in Java, with the implication that it'd be really ineffective. The GGGP then countered by stating the bytecode can be compiled to native code and executed that way. I recountered stating that if the Java is compiled to native code, it's not really Java anymore; the compiler is effectively written using C++. A compiler written in Java has to run on *A* VM, be it from whatever company, otherwise it's not 'really' implemented in Java*.

      *It is written in the language but what's the point? It doesn't even serve as a proof of concept unless you're trying to prove that a compiler executing in native code is implementable, for which you have prior art for sixty years.

      --
      Marxist evolution is just N generations away!
    13. Re:Write a JVM in Java??? by Anonymous Coward · · Score: 0

      Java is the platform. The language is merely a tepid rehash of C++, and without the platform would have gone completely ignored in favor of Eiffel or something.

  371. Real world applications by Gorimek · · Score: 1

    That's simply not true if you expect benchmarks to reflect real world applications. Sure, it might be true for trivial utilities but for applications that stay alive for long periods of time chugging along, which is probably the majority of the worlds useful applications, it makes the results invalid. Or, at a minimum, sets greatly unrealistic expectations.

    Most real world applications I can think of do not have a constant high CPU load. They typically have short peaks of loads and plenty of quiet moments. In such a load pattern, garbage collection can be performed when the load is low, and the GC hardly impacts performance at all.

    1. Re:Real world applications by mrogers · · Score: 1
      In such a load pattern, garbage collection can be performed when the load is low, and the GC hardly impacts performance at all.

      Are you sure? A garbage collection sweep visits many pages of memory, possibly requiring disk activity to swap them in and potentially swapping out pages that you're going to need when the next CPU usage spike comes along.

    2. Re:Real world applications by GooberToo · · Score: 1

      Are you sure?

      Nope. But, I can make some fairly safe assumptions. As Java can be capped as to the maximum memory that it will use. Accordingly, any server application (which, IMO, is what these attempt to capture), is not going to be configured to be paging it's workload. Accordingly, if you're running a java server and you're paging, something is horribly wrong.

  372. Tools by Myolp · · Score: 2, Insightful

    Something that is almost always ignored when comparing programming language is the actual cost of developing something in that language.

    Sure, you can almost always produce faster software in a low-level language. But since there are no good tools for doing this, it costs to much. Developing software using a modern, state-of-the-art IDE like IntelliJ IDEA, NetBeans or Eclipse speeds up the actually development process and allows the programmers to focus on the design, rather than trying to understand an obscure low-level API.

    And no, Visual Studio does not count as a state-of-the-art IDE...

    1. Re:Tools by SnapShot · · Score: 2, Insightful

      Similarly, something this is also almost always ignored when comparing languages is the actual cost of developing something using the libraries available to that language.

      Back in the dark ages (late 80's) I learned to program in Basic, then Pascal, then ADA, then C, then C++ through high school and college. It must of been 8 years of part-time messing around with code before I wrote my first GUI (I luv that MFC!!!).

      Two days after picking up a Java book, I was doing (crappy but they worked) GUIs in Java.

      Two days after that I had database access through JDBC.

      Then is was XML parsing.

      Then is socket communication.

      Then J2EE...

      With every one of these libraries, a critic could potentially have a complaint that "Sun's implementation of X isn't nearly as good as library Y". However, they are available for free to any developer who has Java, they are documented in a thousand books about java, and the Javadoc web pages make sure there is a common way to access the knowledge necessary to learn new features.

      That, I think, is Java's greatest strength. Sure, Qt, Fox, MFC, GTK, Win32, or whatever may be a better (in your opinion) GUI library, but Swing is available to anyone who programs Java on just about any platform. I bet there are some custom ODBC-like drivers that squeeze the last ounce of performance out of your database system, but I bet I can have database access implemented in Java befor you have managed to get the purchase request for your ODBC library past the financial people.

      So, leave the arguments on who can leverage the last performance boost out of a language to the Comp. Sci. PhDs and researchers. If you, like me, are working in a business environment where success is measured in getting a working product out the door that meets the client's requirements, focus on the libraries you have available rather than the language. By that metric, Java comes out near the top.

      --
      Waltz, nymph, for quick jigs vex Bud.
    2. Re:Tools by SumoRoach · · Score: 1

      or people that need that performance boost. If I have a website that serves dozens of millions of page views a day, each little bit counts. And you most definitely notice it.

      Performance is real world, not theoretical.

    3. Re:Tools by Anonymous Coward · · Score: 0

      If you have web site, you need security more than performance; performance can be improved by adding more memory.

    4. Re:Tools by the_duke_of_hazzard · · Score: 1
      The problem comes when you need to analyse why a library isn't working too well for you (in the real world etc etc). Then, if you haven't got the knowledge/background to udnerstand what's really going on and why something would work badly, then you're stuffed.

      You may know SQL very well, but if you don't understand what the query planner's doing then you may end up writting crappy queries and unable to diagnose what's wrong with them.

      APIs/Libraries save you development time, but at the cost of losing power. If all you see is dashboards, you will never know how to fix the engine!

  373. Sure Java might be faster by dtfinch · · Score: 1

    If you write highly modular code and only use the -O2 setting for optimization. I'd have used something like "-O3 -fomit-frame-pointer -funroll-loops", which is what I compile almost everything with. The JVM does loop unrolling and inlining, which gcc doesn't do when using -O2.

    With the exception of the object creation benchmark, I believe that the results would favor C++ if the optimization flags were not so crippled.

    1. Re:Sure Java might be faster by VStrider · · Score: 1

      that is correct. from the GCC docs: Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed[VStrider: read space to speed] tradeoff. The compiler does not perform loop unrolling or function inlining when you specify -O2. As compared to -O, this option increases both compilation time and the performance of the generated code. So...no loop unrolling, no inlining -> no speed optimizations. He didn't use the correct flags for speed optimising, and i think he knew that. His article is at best, misleading. VStrider.

      --
      VStrider.
  374. Regarding Object Creation benchmark by gsasha · · Score: 1

    So, yes, OK, default object creation in C++ may be kinda slow. But the power of it is that you can define (and quite easily at that) your own memory allocator, the C++ version will fly, leaving the Java far behind.
    And you can write a fairly generic and fast memory allocator for C++. One was published in DDJ, January 1999 (disclaimer: I wrote this).

  375. Are you daft? by Julian+Morrison · · Score: 1

    C++ is lame, so, for the race to be fair, Java has to have one leg strapped behind its back? Rubbish. Java CG is supposed to defer memory stuff into efficient rare operations rather than faffing about with allocation and deallocation in the antique manual style of C.

    1. Re:Are you daft? by Anonymous Coward · · Score: 0

      But it's fair to compare C++ without GC against Java with GC?

      Mind you, there are quite a few very good allocation/memory recycle/GC frameworks for C++ too!

      So why demand C++ having one leg strapped behind it's back while you don't ask for it with Java?

      If you're realy going to compare two things, you've got to do it on even terms, else it's just an apple vs. orange test.

    2. Re:Are you daft? by GooberToo · · Score: 1

      LOL. Clearly a java zealot here.

      Hopefully you'll realize that the comparison is still false and everything I stated is spot on. In fact, you didn't state (java wise) anything that I didn't already state.

      Just the same, to be fair, there is absoluetely no reason why delete and new couple be replaced to function in the same deferred manner. So, avoiding GC in java and forcing MM in C++ is clearly a case of a piss-poor benchmark. To create an apples to apples comparison, either java must be forced to collect during it's run or the c++ implementation must be forced to defer. Only then will you have an honest benchmark.

      Until such time, as I originally stated, all of the benchmarks which create tons of objects and then delete them, are invalid. As is, the java benchmarks hide java's true performance. Which, is exactly my point.

    3. Re:Are you daft? by Anonymous Coward · · Score: 0

      I'm actually using C++ right now (with Python), but I have to say most of the C++ proponents here are boneheads.

      First, I'll let you in on the real power of GC: lifetime management. If you haven't worked in a GCd language (lisp anyone?) you are probably missing the entire point. I've worked in C++ off and on for ~12 years and I know how to call new and delete. The power is that in a GC environment you don't have to manage the ownership of objects with either design constraints or reference counting. As programs become more complicated, the ownership of objects becomes more important and more difficult. Asynchronous I/O via callbacks, multiple threads, caches, etc. In a GC environment, just grab the pointer and the lifetime is maintained for you.

      Second, all of this "I could if I wanted to" is pathetic. I *have* written custom allocators over the years, but I don't until I *need* to. And that is the point. In Java, Lisp, et. al. I get one with no programming effort expended. More importantly, custom allocators can be hell when working with 3rd-party libraries.

      Look at the mainstream C and C++ software you are using -- custom allocators are *very rare*. In most Linux distros, I can think of Apache and Subversion, because they use pools from APR.

      However, for those that haven't tried GC, pools aren't the same. You have two approaches with pools:

      1) Allocate/free in a pool, which is the same thing as using malloc/free or new/delete.

      2) Allocate but don't free in a pool, then free the entire pool. This means you allocate and free more pools (via malloc/free) and bundle the deallocates within the pool.

      The problem with this type of bundling (2) is that unused memory in the pool cannot be used. You have decided to temporarily "leak" memory which can be a precious commodity.

      A real GC allocates a pool. Your allocations come from it. You don't deallocate. When the pool is full, unused memory is identified in the pool, the pool is grown, or another pool is allocated.

      Java has a memory manager that works out of the box. You don't have to do anything special to use it. It's fast and it works.

    4. Re:Are you daft? by GooberToo · · Score: 1

      LOL. You seriously think you offered something to the topic here?

      You have decided to temporarily "leak" memory which can be a precious commodity.

      That's sooo funny. If we run with your logic, then that means java is one huge memory leak. That's funny.

    5. Re:Are you daft? by Anonymous Coward · · Score: 0

      Clearly you didn't understand the post. Let me clarify:

      In a GC environment, you don't deallocate, but the runtime can determine which memory is unused.

      If you don't deallocate in a pooled system until you free the pool, the runtime cannot determine which memory in the pool is unused. The unused memory in the pool is "leaked" until you free the entire pool.

  376. Re:Some performance myths by dtfinch · · Score: 2, Interesting

    First of all, g++ actually sucks big time in terms of performance.

    Just in this case, it sucked much more than usual. -O2 is no match for something that does automatic loop unrolling and function inlining. And the loop unrolling doesn't even get enabled in -O3. My own preference is to start with O3 and enable loop unrolling and omit-frame-pointer, which seems to make a noticeable difference.

  377. Looking as the assembly for the C++ code by mc6809e · · Score: 3, Insightful

    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.

  378. Bullshit by baest · · Score: 3, Insightful

    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.

    1. Re:Bullshit by baest · · Score: 1

      Replying to my own post...

      Also I got a 14% speedup using -O3 instead of -02 which he used in the tests. The Java compiler is optimizing automatically so the C++ test should also be optimized as much as possible. So 15% from changing the code and almost 15% from optimizing.

  379. Let's see the primes thing again :-) by RedlumF · · Score: 2

    Ok, here is the java version
    [alex@alkis dev]$ time
    /usr/bin/j2sdk1.4.2_04/bin/java -server sieve 10000
    Count: 1028
    1.94user 0.02system 0:02.08elapsed 94%CPU (0avgtext+0avgdata 0maxresident)k
    0inputs+0outputs (1major+2392minor)pagefaults 0swaps

    And let's see the g++ ...
    [alex@alkis dev]$ g++ -O2 -o sieve sieve.cpp
    [alex@alkis dev]$ time ./sieve 10000
    Count: 1028
    7.64user 0.02system 0:07.84elapsed 97%CPU (0avgtext+0avgdata 0maxresident)k
    0inputs+0outputs (0major+264minor)pagefaults 0swaps

    Should we try intel's c++ compiler?
    [alex@alkis dev]$ icc -O2 -o sieve sieve.cpp
    [alex@alkis dev]$ time ./sieve 10000
    Count: 1028
    0.90user 0.00system 0:00.94elapsed 97%CPU (0avgtext+0avgdata 0maxresident)k
    0inputs+0outputs (0major+284minor)pagefaults 0swaps

    Now, can someone compile KDE/Qt with icc and send it to me, please?
    Thank you!

    /Alex

  380. Re:This doesn't make any sense... by lokedhs · · Score: 1
    Make that 1.2, which is when the Collections framework was introduced.

    It might be that the grandparent post were referring to the foreach construct in 1.5, which allows you to do stuff like

    List<String> someList = ...;

    for( String s : someList ) {
    System.out.println( "s = " + s );
    }
  381. Post review by strider_starslayer · · Score: 1

    While these tests do indeed show that using Java is faster then GCC (which is largely not processor optimised) code written by a java expert with very littel understanding of GCC, it really dosen't 'prove' anything for several reasons.

    1-GCC is not as optimised as other C compilers
    2-He's a java expert, but a poor C programer
    3-his implimentations as a result are better on Java, and worse on C

    So, what I think needs to be done- is for somone to grab the most efficent implimentations (on java and C), send them to him, and ask him to run the test again, so that this way we skip the optimization problems

    As for the GCC problem- I think that GCC is more 'ideal' due to the following scenario- code written in GCC is, at least in theroy, portable to multiple arcetectures- much like a java program; the dammage to performance for that factor should cancel out; IE- were testing two multi-plantform languages, not a platform specific one against a multi-platform.

    These opinions are not my own- I have blatently copied them from others in the thread, but it should help people see what the argument is.

    --
    -Millions of Monkeys, Millions of typewriters, 6 hours of sorting through faeces encrusted pages to find: This post
  382. Matrices by sht_london · · Score: 1

    I had only a brief in the handling of the example code for matrix.cpp file. This code a fine example to slower the performance of code. It is always a bad idea to handle a matrix as a two-dimensional array. Doing so will cause the processor to performe complex calcumaltion of the size of the object. Any experienced coder would use a simple array and small method to calulate the position Something like
    return (iPos_x + iPos_y * iCount_x)

    1. Re:Matrices by Doc+Ruby · · Score: 1

      Don't optimizing compilers replace the hi-level n-dimensional array code with exactly the serializing code you mention?

      --

      --
      make install -not war

    2. Re:Matrices by sht_london · · Score: 1

      They shall/should, but you can not be sure - therefore it just better to make it on your own

    3. Re:Matrices by jeremyp · · Score: 1

      Point of information:

      The computer only has a one dimensional array of memory locations to work with. If in C you define a 2D array e.g.

      int foo [5][5] ;

      it will allocate a single dimensional array and do the exact same calculations you would do.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    4. Re:Matrices by sht_london · · Score: 1

      The "self-calculations" has an other benefit: If have class (template) administrating such a multi-dimensional array, the access calculation method can include checks against dynamical boundaries violations which can produce an error message/exception etc. - A very usefull "side-effect"

  383. A Rant About Java/C++ comparisons by Anonymous Coward · · Score: 0

    Well, I hate Java. I get sick to my stomach when I recall writing a full EDA CAD program in Java, just to see if the language is worth bothering with. I will in fact pay a "mugger" to smash my hands with a hammer and become a burden on the system before I write further code in Java.

    That being said. I like apples and I like oranges. I don't compare them to one another since they each have a unique "being". I do compare the apples within a basket and choose the one which appears most interesting to me. Other times I do the same with oranges.

    I like to develop operating system kernels, web browsers, ans other end user applications. I don't care much for coding web back-ends. I believe the web is obscenely overused for things that would have been better implemented as an application.

    C/C++ and Java are apples and oranges as well. People insist on calling Java slow. Or they brag that C++ is faster. The fact is that given the modern architecture of a JVM, there is no reason to believe that Java is slow. It really is no longer an interpretted language. It is a language which is simply compiled into an intermediate language before becoming an executable. A modern Java VM typically will compile all the code to native when loading a module. The next time the module is loaded, the native compiled version is pulled from a cache instead of recompiling. This means that the Java language in some cases for performance is in fact superior since the compiler group can focus on compiling Java to an intermediate language which another team can focus on compiling and optimizing to the native architecture.

    C++ is also an extremely complex language to implement a compiler for. The preprocessor followed by lexer and parser are extremely difficult to implement. The back end is also terribly hard to design. There are so many differing contexts in C++ that developing an excellent C++ compiler is far more complex than making a Java compiler system.

    Java also offers garbage collection. There are top notch people around the world obtaining Ph.D. degrees in this topic alone. It's far more advanced than a simple reference counter. Constant evolution is occuring making Java garbage collectors kick in at the right times and function quickly. This solves a huge problem related to C++ heap managers. C++ heap managers are incredibly slow. There are of course some heap managers which are much higher performance. Doug Lea's malloc is fast, but not thread safe. There are thread safe incarnations, but they're not as fast. There are commercial heap managers such as SmartHeap which are in fact fast and thread safe, but expensive. In heavy object oriented systems such as web browsers and such, it is likely that performance is going to be hurt severely by heap management and a Java implementation therefore can definately be faster since cleanup typically will only occur in out of memory conditions as well as idle times.

    I still can't imagine any project that I would implement using Java. I would chose a C++ system instead. It has nothing to do with performance. It's just that I find Java to limit my choices drastically. I would prefer a .NET solution using C# if I needed the features in Java that I respect. I just don't like the Java language, it feels like a toy.

  384. And now with Obj-C++ by Anonymous Coward · · Score: 0

    Obj-C++ is an Apple extension that lets you mix and match Objective-C and C++ code transparently and easily, and was just given accepted status by the good folks maintaining the gcc source base. (Not a standard include, but one to be standardly distributed and enabled with the --enable-languages flag at compile time of gcc.)

    You can then do tricks like:

    NSString str = [NSWindow getTitle]; // Objective-C
    cout str.c_str(); // C++

    Very slick, lets you quickly use existing C++ code and libraries while leveraging the new language.

  385. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    And they all have free-form windows, and ignore your system supplied font settings, and don't pay any attention to your current display size, bitdepth or resolution. Like Windows XP Home Edition for a 14 year old female AOL user, but much much worse..

  386. If you want slow... by dave1791 · · Score: 1

    Take a look at my java code sometime. I was recently reading an article on java performance and found that I do everything the way that I am NOT supposed to...

    Well, at least people find my code easily readable/maintainable.

  387. Re:Really? Try this one. by sploxx · · Score: 1

    Uh, no. Java != JVM.
    That's the point. A C++ compiler with a JVM backend and your argument is moot. AND with C++ you have the advantage of using it for lower level things.

  388. Re:That's what happens with the lowest common GUI by Anonymous Coward · · Score: 0

    What the mother of blue fucking blazes is that shit when it's at home? Christ on a fucking pogo stick, you think that doesn't look like a sick dog took a shit on a hot highway at noon? It looks like Plan9 on a bad day!

    People like you (Color blind, asthetically blind, unable to grasp simple design principles, idiots) are the primary reason why Linux user interfaces suck shit. You're fucking deluded or possibly on acid if you think that pile of dog droppings looks good.

  389. OT:Re:PCs are LBAs, and Halting for LBAs is solved by alex_tibbles · · Score: 1

    let me get this straight.
    Run a copy of the program.
    Either a program with input halts or it doesn't.
    If it does halt, then we return true.
    Otherwise, keep track of all past states of the LBA, and if we ever come to the same state, return false.
    PROVE: if an LBA does not halt for a given input, then it will loop through the same state.

  390. the halting problem is related by muyuubyou · · Score: 2, Interesting

    If you convert in the simple and mechanical way you mention, you are not going to improve the efficiency of the algorithm at all. You wouldn't be doing anything else but what the computer is doing by it's hardware stack (which would probably be faster via hardware optimizations).

    What we're talking about here is converting recursive to iterative without using the friggin' stack. That would be finding a mathematically equivalent function that is not recursive. This looks pretty much equivalent to the Halting Problem, or Rice's Theorem for that matter. Trivial for a person in some cases like this, but not easy to generalize.

    If there are heuristics to do that effectively, that I don't know. I will check that document you link to when I have the time.

    In this case, result caching would do. Result-caching takes memory but it makes sense sometimes (not that often, mind you). One of the problems I see here is memory efficiency isn't considered at all. It's ok if your machine is 100% dedicated to a fancy benchmark, but running some memory-hungry java processes like this in parallel would make your computer start thrashing to the HD to a virtual halt.

    1. Re:the halting problem is related by Anonymous Coward · · Score: 0

      You may indeed have plenty of math background, as you claim; your computer-science background is lacking, otherwise you'd call the aforementioned method "dynamic programming" like everyone else does, instead of inventing your own terminology. The textbook you need to read is called "Algorithms and Data Structures", try it, you might find interesting.

      Anyways, dynamic programming can be used in recursive programs just as well as in iterative. It doesn't matter. A recursive fibonacci routine can still use a "result cache" to store prune the call tree, and voila - you have linear run time.

  391. Re:Thanks. Article is a troll. by Anonymous Coward · · Score: 0

    Your obsession with twitter lends validity to his points. Aren't you a Microsoft spy?

  392. It's supposed to be an apples vs oranges test by Julian+Morrison · · Score: 1

    Sure you can turn C++ into Java, after all that's how the thing's made, it's compiled from C or whatever. The test is how the standard language fares. Thus eg, using gjc to "enchance" the java by precompiling it would be cheating too.

  393. Wrong, wrong, wrong. by warrax_666 · · Score: 1
    Compilers are IO-bound, not CPU-bound.

    So wrong that it's not even funny. You know why people aren't advocating buying never hard drives to speed up your compiles? Because compilation is not IO-bound, that's why.
    --
    HAND.
  394. Re:Really? Try this one. by rjh · · Score: 1
    A C++ compiler with a JVM backend and your argument is moot.
    No such beast exists and no such beast can exist. JVM supports neither strong generics nor multiple inheritance, both of which are required for a conformant C++ compiler. You might be able to get a substantially restricted subset of C++ to compile to bytecodes (but you'd lose most of the Standard Library, since generics factor in so heavily there), but it wouldn't be ANSI/ISO C++.

    The "generics" introduced in Java 1.5 are not generics, incidentally.
  395. Re:Really? Try this one. by sploxx · · Score: 1

    Theoretically *AND* practically, you're wrong.

    1. Theoretically, the JVM is equivalent to a finite turing machine and thus able to run C++ code.

    2. There exists such a beast already (but is sadly not up to date and only a small prototype!).
    See here:
    Java backend for EGCS.

    3. There is mips2java which converts GCC mips backend code to the java virtual machine. Google yourself. But this is a kludge, albeit a nice one.

  396. Is the performance that big a deal? by jochend · · Score: 1

    Many people here have argued that C++-code can be optimized to run many times faster than JAVA-code. This is true, in many, if not most cases. The question is, how fast will the code run when you did not take the time to optimize the code to the fullest? You can probably put in more optimizations in your C++ code, but how much time will it take you, and will it really be worth the effort? Some people also remarked that this benchmark tests the OS or the libraries (IO) more then it does the language. True, but can you truly seperate them from each other? You can choose to use a diffirent library, that you know is faster, but I think many developers will stick with what is deliverd with their programming environement. Not many developers have the time to evaluate other implementations, let alone write their own. A third kind of remark that i read, was that you can't really stick these performance figures on the language as such, but that it are really the compiler, linker or VM that you use that do matter. The example was given that if C++ would run in a VM and JAVA would be compiled that the figures would be quite diffirent. This is true, but it is currently not the case. So, I think it is good sense to compare the languages, since each has its preferred/default strategy for being compiled/executed. So, is C++ faster than JAVA? If you put in the extra effort of optimizing, then yes. If you don't , possibly. Is that effort justified? That depends.

  397. Re:Java sucks, pass it on by mrshowtime · · Score: 0, Flamebait

    Funny how nobody can say anything negative about anything on slashdot without being labelled a troll. Java has crashed my computer for the past several years, and now it's crashing my cellphone. Either there are a lot of sucky Java Coders, or the language itself sucks.

    --
    "Jeremy, you need to get to an internet cafe and cut and paste some appropriate sentiments about me from the world wide
  398. Troll? by Anonymous Coward · · Score: 0

    I know Im going to get Troll for this.. but..

    If you want to write a big system with alot of developers, and you cant realy afford to huntdown memory allocation problems you use Java. (Not compleatly true, at my company we found some nice JIT bugs..).

    If you can live without boundery checking, if you can live without objects, if you can live without segfault checks (null pointers exceptions).. then use C.. and I dare you, you will get more performance just cause C uses lesser abstraction between the code and the hardware, but it takes longer time to learn and program in.

    If you can half of half, (the best of the two worlds?) then you can go for an OO C alternative, C++? Object C? ..

    You all see, when it comes down to what language you choose it comes down alot to maintainance, and maybe Java wins there. Java is dead simple, but JIT bugs arent =) .. Saying that Java is faster is to shoot your foot, how can anything with more abstraction layers be faster then something without these checks, and without these code in the memory? I dont understand. Allocating alot of objects in java drag with alot of mutexs and so on. Allocating a piece of memory in C drags with some meta information about size of allocation, but so does it in the JVM also. And I never sofar seen any JVM that actaly optimize the code while its running.. Im sorry but I just havent seen it.

    Performance come mainly from one thing, and thats good algorithms. You can do wounders with good algorithms compared to bad ones. If need to squeese even more performance out of your program, you gotta change language, its as simple as that. Change from Java to C++, change from C++ to C, change from C to Asm.

    Performance is not everything.

  399. Re:Some performance myths by Anonymous Coward · · Score: 0
    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++.
    This is not true, GCC's performance is quite acceptable in most situations these days. I've seen a number of benchmarks in which gcc beats icc(with ipo) in terms of speed. What are you basing your assertions on? Have you actually benchmarked these compilers, or are you just speculating? If you are speculating you should really indicate that. This would seem to lessen the extant to which "performance myths" or propagated.
  400. Re:First Post by Anonymous Coward · · Score: 0

    this is ruducilous, just yk teh articel.

    "teh Java is bettah tahn teh optimiz0red C++" my ASS!

  401. Re:my arse by Anonymous Coward · · Score: 0

    Java is gay.

    I am truly sorry for you; it's nice that you justify it, but really ... just shut up.

    Thank you.

  402. This is Not Good News by Anonymous Coward · · Score: 0

    Great, now all of those people who couldn't get a C++ program to compile and link will be writing enterprise Java applications.

    That was meant to be funny, but I think that it's true to a large degree. Java insulates you from so many aspects of the machine that it allows people with no formal training to make unholy messes out of applications. That's all well and good unless you're stuck on a team with such people.

    Oh well, I imagine the assembler hackers were saying the same thing about C.

    1. Re:This is Not Good News by 09za+ · · Score: 1

      it also alows us to do YOUR job mister cool guy programmer. and guess what? I still do my regular job too. methinks thou need more skills. If we're all so awful, You have nothing to fear ...right? I love hearing that Java insulates you from so many aspects of the machine that it allows people with no formal training to make unholy messes out of applications. I would love to see some programmers build a house so we could all laugh at their ignorance as they ask us how to use a level.
      You guys need to get over yourselves, your skills are easily duplicated.

    2. Re:This is Not Good News by narcc · · Score: 1

      Why is it that every non-programmer has to troll these discussions with statements like: "I would love to see some programmers build a house so we could all laugh at their ignorance as they ask us how to use a level." I seem to recall another discussion where a fellow wanted 'us' (programmers) to do something silly like rebuild a transmission and have it work right on the first try without a manual.

      Well, I'm neither a mechanic nor a carpenter -- I'm a programmer. Can any mechanics or carpenters do my job? Probably not. Do I expect a mechanic or a carpenter to be able to do my job? Absolutely not.

      When I need plumbing done at my house, I call a plumber. When my car won't start, I call a mechanic. I don't try to do those jobs myself, I look to someone with the skills necessary to do the job.

      Now back to the point of the parent post (which this troll missed) Lets use welding for an example.

      Anybody who welds for a living can tell you that welding isn't an easy job, and requires good training. They'll also tell you that there are good welders and bad welders. The bad ones having poor or inadequate training -- or are just fscking stupid.

      The parent poster was complaining that certain tools enable poorly or inadequately trained or fscking stupid programmers to pass themselves off as good programers. (imagine a tool that allows the untrained to make welds that look good, but are truly poor!) This upsets him enough to post on slashdot.

      Should he be upset? Absolutly! Poor programming can kill just as easily as poor welding!

      To the non-programmer to who posted: "You guys need to get over yourselves, your skills are easily duplicated." I call bullshit -- my skills are certainly not easily duplicated, otherwise we wouldn't have this flood of bad (poorly trained and fscking stupid) programmers out in the market. (People who make statements like: " it also alows us to do YOUR job mister cool guy programmer. and guess what? I still do my regular job too.") Just like welding, there are those who are skilled and properly trained and those who are unskilled and inadequately trained.

      Get over yourself, morons are easily duplicated.

    3. Re:This is Not Good News by 09za+ · · Score: 1

      When I need plumbing done at my house, I call a plumber. When my car won't start, I call a mechanic. I don't try to do those jobs myself, I look to someone with the skills necessary to do the job.
      I learn the skills to do these things for myself including web development .. so who's the moron?

    4. Re:This is Not Good News by narcc · · Score: 1

      I learn the skills to do these things for myself including web development .. so who's the moron?

      I'm glad you have the time to learn plumbing, etc. But calling someone a moron for not taking an interest in a particular field doesn't make any sence.

      Though there is the phrase "Jack of all trades, master of none" -- let me know if that fits you.

    5. Re:This is Not Good News by 09za+ · · Score: 1

      actually I master each of them before I move on. I think you called me a moron. I was trying to point out that assuming someone with no formal programming experience will produce a sloppy or bug ridden java program is quite insulting to someone like myself, a self starter, self taught sucessful programmer who has only 3 months invested in this my latest venture. Honestly, I can't wait to see how difficult programming is in other languages but until then it is insulting to hear from elitists who think what they do is beyond the grasp of persons like myself.

  403. Re:Can I have an infinite budget to write the code by Felonious+Ham · · Score: 1

    How? Without examples, your post is essentially a troll. I'm far from Swing's biggest fan (though I have an enormous appreciation for Java after starting out in C++), but throwing together a reasonably complex GUI either by hand or with one of the many (more than QT) visual editors is not hard.

  404. All relative by javajoe99 · · Score: 1
    All this is soo relative to clean code vs. not so clean code, II have looked at some of his benchmarks and read a lot of comments stating well this would be better if you used xx library in C++, the same can be said about the java that was written. Here is an example I read did the stringcat benchmark and get a avg runtime of 600 milliseconds
    import java.nio.*;
    public class StringAppend
    {
    public static void main(String[] args)
    {
    long st = System.currentTimeMillis();
    int n = Integer.parseInt(args[0]);
    CharBuffer cb = CharBuffer.allocate(n * 12);
    for (int i=n; i>n; i--)
    {
    cb.put("hello\n");
    }
    System.out.println(System.currentTimeMillis() - st);
    }
    }
    Notice the difference? NIO buffers are very fast compared to stringbuffer.
  405. Re:Caught up with the speed, but still the ugliest by Decaff · · Score: 1

    SWT are still FAR slower than QT or the Win32 API

    Er no. SWT is the native GUI. Its a library that allows Java to use native GUIs via JNI.

    Saying SWT is FAR slower than something like the Win32 API is like saying that Win32 API is FAR slower than the Win32 API!!

  406. Grain of salt, anyone? by huckamania · · Score: 1

    My only question is, did he come up with the title before or after he started his testing?

  407. its not the code... its the JVM by locutus2k · · Score: 1

    I have studied java in some detail, and my major complaint with Java is not the code, but the JVM. On a windows box, to launch java related stuff, the system has to start the virtual machine which is the painfully slow part.

    I think C++ being closer to machine code than Java would make C++ faster, but would have to read more of what other people have tested regarding actual operation speed of the code.

    Java is a powerful language, and despite my major complaints with it, I have to admit that it will most likely find itself in more embeded devices such as cell phones.

    Just my $0.02

  408. stop the nonsense, moron! by Anonymous Coward · · Score: 1

    before any retard ever claims java is faster again, just write me farcry, halflife2 level of game in java!

  409. Has anyone else realized.... by kook04 · · Score: 1

    that the individual who published this study (Keith Lea) is the the son of a well known Java advocate and Sun Microsystems consultant (Doug Lea)? I'm not implying that this should in any way taint his results. I just found it interesting that Doug Lea was mentioned in this thread by someone listing the pros of Java, and the connection was never made.

  410. Re:Can I have an infinite budget to write the code by swillden · · Score: 1

    but throwing together a reasonably complex GUI either by hand or with one of the many (more than QT) visual editors is not hard.

    Throwing one together is easy, but making it fully functional isn't. For one specific example, have you ever tried to build a dialog with a fairly complex set of controls in Swing that resizes nicely? The whole BoxLayout thing works well and is easy to use as long as your UI fits a certain pattern, but anything that doesn't is pretty hard. Beyond that, Swing is full of little oddities and inconsistencies that trip you up. One that I stumbled across not long ago is that when Swing calculates the preferred size of a pane containing two Boxes laid out vertically, it inexplicably only includes the size of the top box. Setting the pane to its preferred size should require:

    setSize( getMyContentPane().getPreferredSize() );

    But, in fact, it requires:

    Dimension tmp = getMyContentPane().getPreferredSize();
    Dimension d = new Dimension(tmp.width, tmp.height + okButton.getPreferredSize().height));
    setSize(d);

    I'm sure there's a reason, and it may even be a good one, and I could look at the source and find out. But it's not what I expected.

    Swing frequently and consistently violates the principle of least surprise. It's always making me scratch my head, even after reading the documentation, whereas Qt not only rarely surprises me, I frequently find I don't even have to look at the documentation because my guesses as to how it will work are nearly always right.

    In a nutshell, I've used Qt more than Swing, but spent far more time reading Swing documentation and Swing source code than Qt documentation or source.

    To provide some more examples, I'll ask one of my colleagues who has used -- and been frustrated -- with Swing far more than I have to chime in.

    --
    Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  411. Server-side close but GUIs will keep the by mactari · · Score: 2, Insightful

    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 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 any time soon.)

    --

    It's all 0s and 1s. Or it's not.
  412. GCC bad compiler choice?? by Anonymous Coward · · Score: 0

    Somebody PLEASE say that this dude made a bad choice for the C++ compiler. PLEASE say it again. I need to read it just one more time for it to sink in.

  413. yeah, right by twitter · · Score: 1
    One of my personal trolls begs me:

    give us a link. Some PHP or Perl or JSP site, or some project you've contributed to, or your personal project page or some commit log with your name.

    Sure, I'd love to have you assholes do the same things to me and mine what you do to Slashdot. Why don't you check out all the fine code at:

    This site.

    --

    Friends don't help friends install M$ junk.

    1. Re:yeah, right by Anonymous Coward · · Score: 0
      Just one little snippet of code, twit. Not that hard, is it? Most people here on Slashdot are developers - I don't assume you are too, but I'm willing to give you the benefit of the doubt given that you are talking about "free code".

      Or, if you're not a developer, can't write code to save your life and really aren't qualified to comment on an article about programming language performance, please say so.

    2. Re:yeah, right by Anonymous Coward · · Score: 0

      ok, this is weird. either I missed your joke or you've just gone completely off the deep end. voices in your head bothering you much?

  414. I studied CS by muyuubyou · · Score: 1

    But that doesn't mean I have to be an ass and use more terminology than it's needed, so more people (and not only people with CS backgrounds) can understand.

    If you read my post, you will see I mention the H.P. (that was explained in a parent post) and the rest is understandable for almost anyone with, say, secondary education. I believe it's all the education you need to understand this.

    You may have CS background, but your divulgative skills are lacking. Otherwise you wouldn't assume all slashdotters understand what is dynamic programming, or probably you're some elitist mofo who likes to show-off in front of everybody.

    HAND (Have A Nice Day)

    1. Re:I studied CS by fatphil · · Score: 1

      HHL!

      Note that dynamic programming isn't even what real hardcore computer scientists would call it anyway.

      Those with a Lisp or ML background (i.e. the real hardcore beardie-weirdie computer scientists) would simply "thunk" the results. I.e. they'd put the results in a theoretically infinite list implemented using thunks. (Note, these are nothing to do with MS's Win/Win32 cludges)

      Fibonacci is a canonical undergrad Lisp thunk exercise.

      FP.

      --
      Also FatPhil on SoylentNews, id 863
  415. caution about -server by kryzx · · Score: 1


    BTW, I happen to be working on benchmarks for some complex, resource-intensive java software. I tried the switch from -client to -server. It made some things a little faster and some things a lot slower. Using -server may have made a big difference for this guy's benchmarks, but it should not be assumed that it will be better for all applications. Test it and judge for your particular app before making this switch.

    --
    "I don't know half of you half as well as I should like, and I like less than half of you half as well as you deserve."
  416. Re: the new site of the Shootout by Anonymous Coward · · Score: 0

    ... is here :
    http://shootout.alioth.debian.org/index.php

  417. Re: the new site of the Shootout by Anonymous Coward · · Score: 0

    BTW, the maintainers of the new version of the shootout seem to be listening to new suggestions.
    I suggested a wiki in order for people to add new implementations and/or discuss optimizations.
    And they did it !
    So now everyone can add his own grain of salt to the shootout.

  418. Re:Can I have an infinite budget to write the code by John+Harrison · · Score: 1
    It seems that I have been asked to chime in.

    First off, let me say that I like Java a lot and use it more than any other language. I have done some pretty massive swing projects. For instance I wrote the editor that is used to create the documents that describe how to assemble space shuttle motors.

    I have also used Qt, but not as extensively. I have found Qt to be easy to learn, well documented, and logical. Swing is not easy to learn, is reasonable well documented, and is usually but not always logical.

    Throwing together a GUI in a visual editor is very easy in Swing. I haven't done this in Qt. However, the visual editing tools that I have used simple place your components statically, with a set location and size using a null layout. If you resize nothing happens. In order to get good resizing behaviour you have to use the Box and BoxLayout objects. Not only are these poorly documented, but the concepts are poorly named. What is a Box? What does glue do? Not what you would expect from the name. Creating a layout that behaves properly by hand is a painstaking process. If you screw on thing up you'll get bad behaviour that is hard to debug since Swing components tend to behave inconsistently on resize, ie you start at one size, change to a second size, and go back to the original size and your components are laid out differently now.

    I have fond memories of using Power Plant to effortlessly lay out GUIs that could resize and looked nice back in the day. I don't know why Sun hasn't gotten something that works well for Swing.

    Doing layouts by hand in Qt is much easier. The concepts of the layout tool are easy to grasp and work correctly without lots of tweaking.

    I could go into a whole page of complaints about the Swing text package and the abomination that is the document tree, but I will save that for another day. Suffice it to say that it is poorly documented, badly designed, and gives you complexity without functionality. Of course adding that functionality yourself is impossible because of the way that useful methods are private or package private so you can't call them in order to do things yourself. The option would be to edit the source, which would mean that you could never upgrade your Java. Ugh!

  419. twitter is a high-school drop out by Anonymous Coward · · Score: 0

    without a chance in hell of earning a living or doing anything useful in his life. Poor little Twidder.

  420. Worth the effort to learn Java. by dswartz · · Score: 1

    The Java regular expressions feature is documented at the Java web site. Check out the Java forums for more detail. We have all had trouble learning new APIs and becoming familiar with new languages. But, it is worth the time to learn Java.

  421. Re:Caught up with the speed, but still the ugliest by angel'o'sphere · · Score: 1

    I don't know from where your impression about SWING performance comes .... neither on my MAC nor on my PC SWING applications (like CodeGuide, www.omnicore.com) seem in any way slower than native apps.

    Regarding your fibonacci example ... well it crashes ugly if n is reasonable higher than max.

    For you that example might be "optimzed" for C++ ... well, I can rewrite it to java if you like ... so the Java version has no recursion anymore.

    Guess what .... the rest of your comment will then be proven wrong as well: Java will never be faster than properly optimized C++ compiled with an intelligent optimizing compiler except in bizarre corner cases.

    Java does RUNTIME optimization. C++ CAN'T do that. As long as C++ is not compiled to a VM it will fall more and more back behind Java the more the hot spot optimizations get improved.

    HP uses VMs to run PA-RISC machine code on VMs .... gues what? The interpreted MACHINE CODE is faster than the native executed machine code .... after the VM has optimized it more and more. No compiler can do that.

    Just drop the bullshit Java versus C++ arguments. The question is not and was never: Is Java as fast as C++? The question IS: how long can static compiled code remain faster than JIT compiled byte code or ahead of time compiled byte code or hot spot compiled byte code? Thats the question. And the answer is: in the year 2004, static compiled machine code is no longer state of the art. Hot spot like Sun does it currently is "state of the art" and the dynamic compilation/optimization HP is doing is "bejond state of the art". Static compilation has LOST. (And it was predictable in 1998 that it would have lost around of today)

    angel'o'sphere

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  422. Re:OT:Re:PCs are LBAs, and Halting for LBAs is sol by tepples · · Score: 1

    PROVE: if an LBA does not halt for a given input, then it will loop through the same state.

    An LBA with k possible characters per cell, n cells, s possible states of the head, and p possible tape positions has p*s*k^n total states. This finite number of states is the major difference between an LBA and a TM. Therefore, if you run the machine for p*s*k^n + 1 states, it will have either halted or gone through a state more than once. The tortoise-and-hare method is a convenient optimization derived from a method given as an algorithm in The Scheme Programming Language to detect cyclic lists.

  423. Re:Java faster than optimised C++ (Um, it's online by Ebola_Influenza · · Score: 1

    HA Ha HA Ha HA Ha HA Ha HA Ha
    HA Ha HA Ha HA Ha HA Ha HA
    ahem...

    --
    "turning espresso into code..."
  424. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    Er no. There's still a fair amount of wrapping that needs to be done.

  425. Re:Really? Try this one. by CoughDropAddict · · Score: 2, Insightful
    Given *any* algorithm, I can come up with a c++ implementation that is faster than a Java implementation. Period.
    I'd like to see a C++ implementation of the Halting Problem that's faster than a Java implementation, please, thank you.

    Oh, wait, you can't do that because nobody can write Halting.

    I guess that means there are some algorithms for which you can't write a faster C++ version.

    Actually his statement still holds. No algorithm exists that can decide the halting problem, so he can still say "for all algorithms, a C++ implementation can be written that is faster than a Java implementation."

    But don't let me get in the way of you admiring how wise you are.

    Next time, try less rhetoric and more facts. "There exist lots of algorithms for which I can code a C++ implementation that's faster than a Java implementation" is good. The instant you make a unilateral statement like the one you just made, though, it shows that you don't know as much about computer science as you think you know.

    Get off it. Apparently you don't know as much about logical reasoning as you thought, or even Computer Science since you tried to call the halting problem an algorithm. Not to mention that the word "unilateral" makes no sense in this context; you probably meant "unequivocal" or "unqualified." Shall I find more things to pick on?

    (Normally I wouldn't be this pedantic, but you are ripping on someone else based on pedantry and being rewarded with +5.)

    Fact: there exist cases where Java is faster due to its ability to optimize on the fly.

    The whole point of this critique is that any run-time optimization that Java can perform, a human can perform when they write the algorithm. In the end, all programs are executed by running machine instructions, and any set of instructions that a JVM emits/executes, a human can write manually to achieve exactly the same performance.
  426. Bah, real programmers... by Anonymous Coward · · Score: 0

    ...program in assembly.
    you get all kinds of speed from that

    Actually, the results are surprising, but it is an apples to oranges kind of comparison

  427. YesAndNo by sht_london · · Score: 1

    Of course it possible to transform a function of the type

    a_n+1 := f (a_n) into a_n := g (a_0, n) This is not the question. By using a recursion the problem is: Does it makes sense: How much Stack I will need in worst case scenario? How much the calls, pops and pushs will effect the performance? Is it worth to pay this prize? Often enough I would say: Yes, but not always.

  428. Re:Caught up with the speed, but still the ugliest by Decaff · · Score: 1

    Er no. There's still a fair amount of wrapping that needs to be done.

    No. Part of the design of SWT was to ensure that there was absolutely minimal wrapping. API calls in the native GUI (e.g. SendMessage in Win32) are mapped directly to identically named API methods in the Java implementation of SWT for that platform. Then, an thin object layer of the GUI above that provides a common model of the GUI for all platforms.

    On windows, something like the '.setText()' method in SWT is a call to a Java SendMessage which calls the Windows SendMessage function via JNI.

  429. Why not try a REAL WORLD comparison? by DreamCoder · · Score: 1

    It doesn't make much sense to do line-for-line comparisons between Java and C++ and then argue over the results. A more productive approach would be to define a set of requirements for a real-world application, and then set off to develop a version of this application in each of the two languages. Each implementation may take advantage of whatever features its language has to offer, including it's own standard library.

    The results of this activity should be measured objectively based on speed, memory usage, correctness, stability, and the amount of time required to implement it.

    As a follow on, it would be interesting to add additional requirements in order to evaluate how well the implementation can be extended and/or modified.

    This would make for an interesting competition, and would be alot more fruitful than this discussion.

  430. bootstrapping by GCP · · Score: 2, Interesting

    Many compilers and interpreters are written in themselves. Read the other comments about bootstrapping. And how do you think the first C compilers were written? In C?

    When you understand bootstrapping, you'll understand how one would create a JVM written in Java. (IBM did just that.) It's not a question of whether it is possible, but what the pros and cons would be.

    --
    "Those who have never entered upon scientific pursuits know not a tithe of the poetry by which they are surrounded."
  431. Following up by emarkp · · Score: 1
    After taking the 'methcall.cpp' file and removing the dynamic allocation, the runtime was 3.5 times faster. I suspect that was due not only to the call to new and delete but because of a faster function dispatch with the object on the stack as compared to the heap.

    Just goes to show you how worthless these benchmarks are unless you have an expert implementing for each language writing code like you would in real life and the tests aren't aimed at the benefits of one language or another.

  432. Re:my arse by cardshark2001 · · Score: 1
    *sigh* have you people never heard of runtime optimisations?

    Have you never heard of self modifying code? Look it up. You can do it in c++. You cannot do it in Java.

    But really, the question here is whether a generic run-time profiling algorithm can outperform a human with time on his (or her) hands and a good profiler. Why isn't Carmack writing Doom 3 in Java? Is it because he is biased and religious? Or is it maybe because the performance isn't there?

    With c++, you can take advantage of architecture specific optimizations. What you are talking about are algorithmic optimizations, which are good, and make java perform better than it otherwise would, but can't approach the performance that a skilled technician in the art can get from c++ by writing well optimized code and profiling the actual generated assembly code.

    Furthermore, the specific optimizations you name could be implemented in c++. The compiler won't do it for you, but a clever enough developer could do them, and the end result would outperform Java because there isn't a virtual machine profiling the executable constantly, trying to figure out what to do.

    My point is that proper design-time optimization is going to be better than compile-time optimization no matter what. No algorithm can yet approach the intelligence of a human when it comes to optimizing.

    We're arguing about seperate things. You seem to view optimization as something the compiler does, and this seems to be a common view amongst java programmers. Real optimization involves knowing your compiler, knowing your architecture, and writing smart code to take advantage of both. No matter how smart you are, you can't take advantage of your architecture in Java. You have to rely on Java to do it for you. The whole point of java is to remove you, the developer, from the architecture.

    --
    WWJD? JWRTFA!
  433. distinction without a difference by GCP · · Score: 1

    There's no difference between an interpreter and a compiler in this case. Both take some Turing complete human-ish language (source code) and convert it into Turing complete machine instructions, which is all that the CPU understands. You could do all sorts of crazy things, a C *interpreter* written in Excel macros, for example. It just takes source and turns it into machine code, and the only question being addressed here is which technique results in faster ultimate execution of machine instructions and interactions with memory, the C++ source compiled into a wad of machine code in advance approach or the Java source compiled in advance into a wad of bytecode which is then compiled incrementally and cached by a JIT process approach. Each one allows for a different set of optimizations that convert the intent expressed in the original source into the closest thing to the minimum work the processor needs to do to carry out those intentions.

    --
    "Those who have never entered upon scientific pursuits know not a tithe of the poetry by which they are surrounded."
  434. Re:Caught up with the speed, but still the ugliest by Sivar · · Score: 1

    I don't know from where your impression about SWING performance comes .... neither on my MAC nor on my PC SWING applications (like CodeGuide, www.omnicore.com) seem in any way slower than native apps.

    SWING tends to get slow when many controls are used. I am not sure what the specifications of your computer are, but try running a complex Java GUI app (one which is similar to a non-MFC Win32 app or a QT app for comparison) on a slower machine, or write up a quick test program which plays with 15 or so controls (hiding them, moving them, adding/removing data, creating them, etc.) a set number of times both using SWING and using the Win32 API or QT. SWING is quite a bit slower. Perhaps this has been improved in 1.5, but it is certainly the case in 1.4 and earlier.
    Regarding SWT performance, I've yet to see an example of a responsive, large SWT-based GUI app. Eclipse, while it is very nice in many ways, is slower than a dead slug stuck in frozen molasses compared to Microsoft Visual Studio or KDevelop, at least, in my experience. Perhaps I will have to try a server VM.

    Java does RUNTIME optimization. C++ CAN'T do that. As long as C++ is not compiled to a VM it will fall more and more back behind Java the more the hot spot optimizations get improved.

    I can see that runtime optimization has a few minor advantages. For example, a JVM can utilize processor-specific optimizations even if the CPU type is not known at "compile" time. That said, C++ and other compiled languages can do the same if the architecture is known (-march=). Because optimization is done at compile time, optimization time is not a very important factor, and the compiler can freely tune the hell out of the code. What optimizations can a JIT compiler do that a non-JIT compiler cannot? Let's say it sees that a function is being run quite a lot and the JIT decides to inline it. Well, C++ compilers are very good at guessing which functions will be run very often and inlining them, and the programmer can explicitly state that the function should be inlined if desired.
    Does the JIT try thousands of possible ways of executing the same code to see which is the fastest? That would be something that a C++ compiler cannot practically do, but compiled language optimizers are so finely tuned that I doubt there are many instances where a modern compiler, particularly an intelligent one such as Intel's or Compaq's, choose a path that is significantly slower than the best a JIT can come up with. That said, compiled languages would not have the overhead of optimizing the code at run time, not to mention the overhead of initializing the JVM. I realize that the latter is just at startup, but startup time is a problem in many modern applications more than run time. OpenOffice is a good (but extreme) example.

    Further, Java lacks direct access to pointers, which allow for many snazzy optimization tricks, and cannot compare with compiled languages for bitwise operations.
    Perhaps I am not a sufficiently talented Java programmer, but I know of no way to do something like

    if(ch >= 'a' && ch <= 'z') ch = ch&0xDF;

    in Java, and I doubt that Java's JIT could figure out a similarly fast way to convert an ASCII character to uppercase, let alone a more sophisticated algorithm.
    Granted, in the RealWorld, developers do not often use ugly optimization hacks for readability and maintainability reasons alone. In those cases, pretty code in Java and C++ are likely comparable. Java probably has the advantage in many situations (as shown in the benchmarks in the article), but Java is a higher level language--It is much more removed from the machine, and as such, can never consistantly beat a sufficiently talented programmer until JITs begin including AI.
    Because you can have a strong measure of control over the code that is generated (going so far as to use inline asm if needed), there is no situation in which Ja

    --
    Computer Science is no more about computers than astronomy is about telescopes. --E. W. Dijkstra
  435. Re:Can I have an infinite budget to write the code by Felonious+Ham · · Score: 1

    To be honest I haven't done a ton of Swing lately (I think it's too slow on a 1.6Ghz T40)--for the little GUI projects that I do I use SWT. Much faster and native look and all that. So while my recollection of Swing development may be a bit dim, I'm familiar with working with a new GUI toolkit.

    SWT has it's own layout manager similar to GridBagLayout in Swing. At first it seems like complete rubbish, but after a while it makes sense. The point, though, really, is that GUI development can be a PITA and if you get a decent editor such as Jigloo, you can get stuff to look 85% right without having to do a lot of layout math.

    Incidentally, I didn't actually expect you to respond ;). I think I even hit the problem you describe, of creating (in my case a generic template) dialog. The content pane where the message or business widget or whatever would show was always cut off by the button pane, despite doing essentially what you did.

    I'd actually like to do some Linux desktop development, but my expertise is in Java and as an Eclipse fanboy, I'm pretty much committed to SWT for the near future.

  436. Re:my arse by kaffiene · · Score: 1

    Self modifying code takes a performance hit on modern processors because you have to flush the instruction cache.

    Additionaly, you can get a somewhat similar feature in Java by compiling and loading code at runtime (not trivial with C++)

    The fact that Carmack isn't writing Doom 3 in Java probably means that his tools are better for what he wants to do, not that Java is slow. Additionally, how many games dev tools and pipelines are written in Java? None, it's only an option now (it has been too slow before) and so it's new on the block when C/C++ have long established tool sets and libraries for them. Noone will throw away their investment in tools for a new language unless it offers significant advantages over what they already use - which Java probably doesn't do, even if it has similar performance.

    You say proper design-time optimisation is better than compile-time optimisation. This is true, but it is just as true for Java as it is for C++. Smart java code is faster than dumb java code just as the same holds for C++.

  437. Digital did a similar thing with FX/32! by Anonymous Coward · · Score: 0

    Digital did a similar thing with the FX/32! x86 emulator/translator, which would let you run Windows NT/x86 programs on NT/Alpha. (A similar program existed for Linux as well.)

    As you ran the application, it would cache the Alpha-native code generated by the emulator, and save the parts that seemed consistent between runs.

    It was especially nice with NT Terminal Server on Alphas, where multiple users running the same x86 program would actually see a speedup after the first person started up.
    (FX/32! was a PITA to apply to Terminal services apps but I managed to get it working eventually...)

  438. Re:Really? Try this one. by Trinition · · Score: 1

    Once again, static compile-time optimizations cannot match run-time optimizations unless the compile-time optimization is to write out every possible code-path that is most optimal for the entire input space. Now, you could write your program such that it analyzes its own runtime state and switches code paths while running -- but that is no the compiler making the optimization. And, at that point, you may say it is human-optimized, so it's better...

    But then you might as well also point out that human-optimized C code can beat out C-compiler-optimized C code.

    FWIW, I've heard arguments that even that isn't true because humans are extremly biased and a computer can just see things for what they are in terms of bits and bytes without getting distracted by our human abstractions.

  439. Re:Really? Try this one. by Trinition · · Score: 1

    Uh, no. Java != JVM.

    Did you see a definition for Java somewhere in the benchmark writeup? Certianly Java is not in its entirety defined by the JVM, but the casual term "Java" is an unbrella term that certainly includes a JVM.

    This lack of an explicit definition is one of the problems with the banchmark. Did he mean the language? The standard libraries? The VM? The version or vendor-specific implementation so of the standard libraries or VM?

  440. Re:my arse by Trinition · · Score: 1

    Have you never heard of self modifying code? Look it up. You can do it in c++. You cannot do it in Java. Could you be more specific? I mean, having a code path that chooses replaces part of its functionality could be termed "self-modifying code". You can infact do that in Java with the Functor pattern. If you mean actually modifying discrete portions of logic without the aid of virtual functions that can be replaced, then wouldn't that be exactly what the HotSpot is doing? Now, perhaps you can't do that in the Java language. But, can you do it in JVM bytecodes (other languages can be compiled to JVM bytecode)?

    With c++, you can take advantage of architecture specific optimizations

    You have that in Java as well. The JVM, being part of Java, is certainly allowed to be written differently for different architectures -- and the HotSpot VMs by extension can re-arrange the machine code it JIT'ed to be more optimal for the hardware at hand.

    Furthermore, the specific optimizations you name could be implemented in c++. The compiler won't do it for you, but a clever enough developer could do them

    This is teh same argument ASM programmers used against higher-level languages, and the same argument C programmers made against C++. If you're such a hard-core hand-optimizing code freak, by not write your code in your favorite hex editor as the actual machine instructions. This is what the authors of Comanche Maximum Overkill did years ago (sorry, it's so old My point is that proper design-time optimization is going to be better than compile-time optimization no matter what. No algorithm can yet approach the intelligence of a human when it comes to optimizing.

    I disagree. Runtime optimizations are basedon the actual state of a running system, nto a developer's pre-conveived notion of what it will encounter. Profiling can get you part of that, but only if you profile for every possible input. Have you never sat down and watched a user use your program and realize, "hey, that user is using it in a way it wasn't designed for!". Runtime optimizations could handle that, but for all of the intelligence of a human, we're biased, short-sighted and emotional (just look at some of the posts in this thread!)

    The whole point of java is to remove you, the developer, from the architecture.

    Yes, you're right! Well, no you're not becuase that's not the whole point of Java. But the underlying point is still true.

    With Java, you let the friggin machine do the work of optmizing it for where you're deploying. As we've seen elsewhere in this thread, you can use special nitty-gritty flags on C++ compilers to target certain architectures. But how often do you do to a page to download binaries and see one compiled for your exact stepping model of the Pentium III? You just don't. Sure, open source has the advantage that you can get teh source and compile it for your hardware, but that does not help the rest of the non-geek world. Maybe if machines saw a *.c file and when you double-clicked it, it automatically compiled it specifically for your machine and exeucted it users would adopt that. But even then, the statically-compiled binary will not have runtime optimizations unless it is hand-coded in. That takes me back to my earlier point that if you want to sit in the dark corners writing tight device drivers in machine code, go ahead -- but the rest of us need to get paid at jhobs where performance is measuredn ot just in how fast your application runs, but in how long it takes to get it done. And while you're may be 3% faster, mine will be developede in 3% of the time that yours was.

  441. Re:Really? Try this one. by CoughDropAddict · · Score: 1

    Once again, static compile-time optimizations cannot match run-time optimizations unless the compile-time optimization is to write out every possible code-path that is most optimal for the entire input space.

    I realize this. Grandparent didn't acknowledge that every possible optimization that a JVM performs is inherently available to lower-level languages also (even if it's not convenient, or idiomatic) with his silly "Fact:" spiel. What bothered me more was his resort to pedantry and his attitude.

  442. Re:Really? Try this one. by Trinition · · Score: 1

    What bothered me more was his resort to pedantry and his attitude.

    Agreed. Sometimes, though, I'm just as guilty. I love Java. And I'ma guy who went BASIC->C->ASM->C++->Java (with some unimportant tangents along the way). I'm not saying it's 100% better than C++ either. The part I get emotional about is the absolutists who can't believe Java could ever be better than C++ in any way. Unfortunately, the benchmark which started this thread -- while done with good intentions -- does nothing to further Java's cause.

  443. Re:Can I have an infinite budget to write the code by swillden · · Score: 1

    I use SWT. Much faster and native look and all that.

    SWT is one I haven't fiddled with yet. I'm sure I will eventually, but for work everything we have is in Swing and for fun I prefer to write Qt.

    I'm familiar with working with a new GUI toolkit.

    I've used Swing, GTK, Qt, AWT, MFC, Win32, ObjectWindows, Liant C++ Views, zApp, the NeXT Devkit, TurboVision, and two UI toolkits I wrote myself (one for DOS-based graphical applications and one for a small proprietary operating system). There may be one or two that I've forgotten, as well.

    Out of all of those I only hated MFC and raw Win32. GTK, Swing, AWT and zApp all fall into the category of "usable". I liked OWL, Liant, TurboVision and both of my toolkits (though they were clearly inferior, functionally). Qt and the NeXT Devkit are the only tools I found fun to use, though Qt is still well below the NeXT stuff, at least to my biased recollection.

    I'd actually like to do some Linux desktop development, but my expertise is in Java and as an Eclipse fanboy, I'm pretty much committed to SWT for the near future.

    I'm sure SWT is perfectly serviceable, and Eclipse is an excellent tool.

    --
    Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  444. Re:That's not quite the point by Anonymous Coward · · Score: 0

    It's the first time an AC trumped me.
    You win this time, Batman!
    Damn meddling kids.

  445. GC vs Delete is not the point by th4tGuy() · · Score: 1

    I think it is not the intention of the bench mark to make the languages run in the exact same manor. I think the bench mark would be much more useful if it exploited all the features of each language, and then measured how fast it accomplished the task. The fact that Java uses a gc system where as C++ forces the programmer to keep tighter track of memory usage doesn't mean Java is cheating. That is the design of the language. If the intent of the application is to occupy as small a memory foot print as possible - then C++ has some advantages.

    Forcing Java to behave like C++ or C++ to behave like java doesn't really have much to do with the bench marks.

    Now poorly written code in either language would make the bench marks more susceptible to criticism.

    --
    -- As soon as I have an interesting sig, you'll be among the first to know!
  446. Re:Really? Try this one. by Anonymous Coward · · Score: 0

    The halting problem is not an algorithm - it can be proven that any "solution" will always have the possibility of non-termination.

    An algorithm runs within a finite amount of time.

  447. Re:my arse by cardshark2001 · · Score: 1
    • With c++, you can take advantage of architecture specific optimizations
    You have that in Java as well. The JVM, being part of Java, is certainly allowed to be written differently for different architectures -- and the HotSpot VMs by extension can re-arrange the machine code it JIT'ed to be more optimal for the hardware at hand.

    You replied with a non-sequitur. What I said is that in c++, you, the developer can take advantage of the hardware. What you replied with is that the JVM can take advantage of the native hardware too. Don't you see how those two things are not equivalent?

    With Java, you let the friggin machine do the work of optmizing it for where you're deploying.

    Yes, and that's great, and it's well suited to certain tasks. However, a general purpose run-time profiler/optimizer is not going to outperform a proficient human. When you absolutely need to count every clock cycle, like if you were writing Doom 3, f'rinstance, you simply can't rely on a smart JIT compiler. The profiling itself is a performance hit. If you knew enough about to Java architecture to implement your algorithm in the most optimal way from the start, the profiler would slow down the run-time.

    With c++, you can examine the native code, and if the compiler does something stupid, you can drop down into assembly and get your hands dirty removing pipeline stalls, making sure your inner loop fits in the cache, and other stuff that you just have to hope the JVM will do for you if you are a java programmer. If the JVM does the wrong thing, you're stuck.

    I'm not trying to knock what is obviously a highly favored language of yours; believe it or not I've written some Java myself, and I'm not a language bigot. I'm just saying, use it for what it's intended to do. Fastest performance isn't it. Reasonable performance with good cross platform compatibility is the best you can hope for, and all it was ever intended for.

    --
    WWJD? JWRTFA!
  448. All iteration in Scheme uses recursion by Jonner · · Score: 1
    From the introduction of the Revised5 Report on the Algorithmic Language Scheme (R5RS), which is the primary current Scheme standard:
    By relying entirely on procedure calls to express iteration, Scheme emphasized the fact that tail-recursive procedure calls are essentially goto's that pass arguments.


    The "do" and "named let" syntaxes are called "library syntax" in R5RS because they are defined in terms of truly primitive syntax like procedure calls and lambda. Since Scheme's syntax is extensible, it needs a very small amount of truly primitive syntax.
  449. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    what

  450. Re:Really? Try this one. by cardshark2001 · · Score: 1
    The part I get emotional about is the absolutists who can't believe Java could ever be better than C++ in any way.

    Yeah, and I must admit guilt for stirring up the pot a bit. Looking back at my original post, it seems like that was what I was saying, even though it wasn't what I was saying.

    Naive java can definitely be faster than essentially the same code in c++. That's a fact, and I don't think anyone is disputing it. The author (troll?) of the /. story just pushed my buttons with his terminology. His idea of "optimized c++" was a compiler switch, and there is so much more to optimizing than that, it just is not funny. I wonder if he knows what a pipeline stall is? My guess is no, given the sorry state of his "optimized" code (well covered by others in this thread).

    --
    WWJD? JWRTFA!
  451. You're disappointed for the wrong reasons by thekm · · Score: 1

    Java never sold itself as the fasted gun in the west.

    And of course you'll write Java to take advantage of HotSpot and the GC running when it needs to. Why?... because for the time being (up until the GC turns over) you end up with an app that can rub noses with C++. This article does prove that.

    You need to add all the other great features of Java... the most important being that it's a very pragmatic system to code in (no need to explicitly free memory etc etc), Java is a fantastic thing.

    The fact that it can HotSpot and have parts of an application go toe to toe with C++... it makes me a truly happy Java programmer.

    It's another topic, but people also deny its cross platform nature, but it does deliver on this promise. I needed to quickly run a complex IDE (IntelliJ's IDEA) on a linux box, but no Linux version of it. By simply copying the Jars from a windows box and starting it up, it was usable without a problem.

    Personally, Java's the bomb!

    1. Re:You're disappointed for the wrong reasons by GooberToo · · Score: 1

      Java never sold itself as the fasted gun in the west.

      This is certainly true. They sold it as write once, run everywhere.

      because for the time being (up until the GC turns over) you end up with an app that can rub noses with C++. This article does prove that.

      Actually, that's been pretty well debunked within the many threads offered here. What is seems is that it proves that given non-realistic corner cases where hot spot shines versus poorly written C++ code compiled via a less than optimal compiler, java can be as fast, if not faster.

      You need to add all the other great features of Java... the most important being that it's a very pragmatic system to code in (no need to explicitly free memory etc etc), Java is a fantastic thing.

      That, I certainly agree with. In fact, I'm willing to admit that the many studies which show higher deliverability with Java are probably true. Thus far, to date, I've yet to actually ever see a valid java benchmark which put java on the same page as C++, in terms of performance. While I've not finished looking at all the code, thus far, it does not appear that these will be that exception.

      The fact that it can HotSpot and have parts of an application go toe to toe with C++... it makes me a truly happy Java programmer.

      But, thus far, we have no proof to support such a statement.

      It's another topic, but people also deny its cross platform nature, but it does deliver on this promise. I needed to quickly run a complex IDE (IntelliJ's IDEA) on a linux box, but no Linux version of it. By simply copying the Jars from a windows box and starting it up, it was usable without a problem.

      Again, I good point, which I agree with. Java is a very good system for pragmatists. It's just not a high performance system in the real world.

      Reference: Fixed hash code thread

      Latest results:
      cpp-optimized: 6.54user 0.02system 0:06.77elapsed 96%CPU
      cpp-slight-opt: 7.99user 0.02system 0:08.21elapsed 97%CPU
      cpp-original: 19.65user 0.07system 0:20.17elapsed 97%CPU
      java-server: 14.93user 0.10system 0:15.67elapsed 95%CPU
      java-client: 17.43user 0.10system 0:19.01elapsed 92%CPU

      So basically, proper code yields a little over twice (2.2x the server version and 2.7x the client version) the performance of a best-corner case for java's hotspot. That's not exactly close.

  452. Re:Can I have an infinite budget to write the code by 0x0d0a · · Score: 1

    Unix GUIs are far easier to implement with Java than with C++. Athena/Xlib are a huge fargin' hassle and no-one ever gets the widgets right. Motif is too expensive to license.

    Whoah, there. This was right...a number of years ago. GTK and Qt have neatly reversed this. It's much more of a pain in the ass to do, say, a Win32 GUI than it is a GTK or Qt GUI.

  453. Re:Can I have an infinite budget to write the code by Anonymous Coward · · Score: 0

    Swing faster than Gtk? Maybe in some fantasy universe. Gtk isn't even overly efficient, but suggesting Swing is faster is just insane.

  454. I'm also european by muyuubyou · · Score: 1

    That's why I studied three times more Prolog than LISP ;)

  455. Re:my arse by Trinition · · Score: 1

    Don't you see how those two things are not equivalent?

    Yes.

    However, a general purpose run-time profiler/optimizer is not going to outperform a proficient human.

    This is one point we'll continue to disagree on. The theory behind runtime optimizations is that there are some things you can' know ahead of time or some conditions that simply aren't static. Again, a "human" could hand-code his application to do runtime proofiling and choose diferrent predefined code-paths based on that... is that what you meant -- essentially building in a runtime optimizer?

    With c++, you can examine the native code, and if the compiler does something stupid, you can drop down into assembly and get your hands dirty removing pipeline stalls, making sure your inner loop fits in the cache, and other stuff that you just have to hope the JVM will do for you if you are a java programmer

    You do have an intermediate option. You can disassemble the classfile (standard JDKs come with the tool named 'javap' for this), look at the JVM Instructions and see if they are doing something stupid. Some crazy minded folk have hand-coded Java machien instructions and built *.class files themselves. There are also a handful of other languages you can compile ot the JVM which may give you more control over what you are doing.

    But, that's not controlling it in Java. In that case, you stil have an option. There are times when I've decompield a Java class file, looked at the JVM instructions it used, and realized if I coded my Java program diferently, the compiler would generate different instructions that would be fewer and faster.

    Fastest performance isn't it.

    I still have a faith that Java will be faster than C++ in some cases. The fact that this benchmark was flawed doesn't mean it isn't true. I certainly don't believe it to be true ubiquitously for all cases. BUt blanket statements like "Fastest performance it isn't" are just too absolute for be to pay attention to.

  456. Re:Can I have an infinite budget to write the code by HuguesT · · Score: 1

    Two questions:

    1- Which GUI toolkit did you use for the C++ application?

    2- Which GUI toolkit did you use for the Java implementation?

    Had you given any thoughts of using a modern C++ toolkit for the re-implementation?

  457. Re:Caught up with the speed, but still the ugliest by Anonymous Coward · · Score: 0

    I wouldn't you expect you to understand. Now go along and play with your Linux computer, newb.

  458. Check your facts. by Paradox · · Score: 1
    No it's not. In fact, it's not even close to the definition of the "halting problem". The Halting Problem is "Given input X, and program Y, will Y ever finish it's calculation, and halt on when given X as an input". It's a 'problem' for which no computer program can be written to solve.

    It has nothing to do with whether or not a compiler can convert a recursive algorithm into a non-recursive one.

    You need to work on your compsci fundamentals. Many problems involving source code transformation reduce to the halting problem. The question that the compiler is asking in a general case destructive-recursive-to-destructive-iterative is, "Are these two programs equivalent?" This is clearly a case of the halting problem.

    In practice, these kinds of optimizations can be pulled off in special case scenarios because the optimizer knows, a priori, about them. I would not be surprised if Sun's optimizer programmers threw this one in, maybe as a proof of concept or maybe for fun.

    In theory, the only way you can really do this kind of transformation reliably is to make your program very simple. One of the reasons that functional languages like removing destructive operations and enforcing stateless functions is that it makes these kinds of optimizations easy.

    Scheme for example, enforces optimization of tail-recursion to a loop. This is a hard problem in general, but Scheme's design has the consequence of making the optimization practical to do consistently.

    Common Lisp. on the other hand, doesn't have such a simple basic structure and as such can't promise things like this.

    --
    Slashdot. It's Not For Common Sense
  459. Just FYI by GooberToo · · Score: 1

    Just FYI, using a GC with C++, changed the benchmark to:

    c++: 14.66user 0.02system 0:15.14elapsed 97%CPU
    java-server: 17.60user 0.62system 0:18.84elapsed 96%CPU

    And, there is still significant room for improvement in the C++ implementation. I see that some have even done GC work which specifically targets transient object creation and destruction. My point being, there is nothing but up for the C++ objinst benchmark. Other prospects would be to simply look at other heap managers as well as simply writing a custom heap manager specifically targeting these transient benchmarks which would reduce the number of deletes to two or three (versus 200,000,000) and completely avoid the overhead of object destruction (currently, 200,000,000). This final solution, I believe, would put it on par (implementation wise) with what the JVM is doing. But, even without an apples to apples comparison, C++ is already taking the lead.

    Thus far, I have submitted back four improved benchmarks back to the tester. All that I have submitted back, have been faster than the java implementation. Oddly enough, while attempting to create some additional benchmark runs which would help further remove noise, I started running into some serious problems with java. Bluntly, some of the benchmarks can not be run with java because java runs out of memory on my system (I only have 512M). Even after increasing java's memory up to the ceiling of my free ram, java is unable to complete the benchmark, having run out of memory. In one such test, the c++ code finished in 1.99s while the java code ran out of memory after 6+s. Worse, the c++ code used about 50+M of ram while the java code ran out while attempting to use 380M. Oddly enough, the more work you asked of java, the worse java seemed to do. In my additonal tests of the strcat benchmark, performance tilted toward C++ ranging from 29% to over 300%, depending on the amount of data being processed and which JVM options were being used.

  460. Re:Can I have an infinite budget to write the code by Felonious+Ham · · Score: 1
    I haven't used the document tree, and as I mentioned to a sibling post, I haven't had much experience with Swing recently. But: while getting the hang of layouts can be tricky, I think that this really is a task best left to one of the many GUI editors out there. The problem with tools, I'm sure you'll agree, is that they produce ugly code, but cleaning up usually takes way less time than doing the layout math by hand.

    I realize this is a pretty poor apology for Swing, but the fact is I've found it to be basically ok, well documented, and the Web is riddled with example code if there's something particularly knotty (or unintuitive) to work out. I can, however, appreciate the pleasure of working with well crafted tools (as I suggested in the other post, the Eclipse IDE is my current favorite scalpel), so even though I'm basically a Gnome guy, based yours and the sibling's posts recommendation, I'll take a crack at this Qt stuff ;).

  461. Re:Can I have an infinite budget to write the code by John+Harrison · · Score: 1

    I used the Visual Age for Java layout tools. I actually don't think that they generated bad code at all. In fact it was pretty good code. I haven't used the WASD layout tool as much so I don't know about its generated code. In any case the layout tool is great for something that doesn't need to be flexible and doesn't need to resize or work at different resolutions. Otherwise you have to do layouts by hand. The basic layouts are easy to understand but look like crap. To produce a really professional looking layout takes a lot of effort and tweaking with Swing. I wish it was easier.

  462. Re:Can I have an infinite budget to write the code by John+Harrison · · Score: 1

    You never used PowerPlant? That was sweet.

  463. Ways to start by SuperKendall · · Score: 1

    You should really post questions non-AC, as otherwise people can't see you responded... it was only by chance I even saw your message.

    Anyway, the best profilers are things like OptimizeIt (built into JBuilder now) but that's pretty expensive - worth getting a licence for a business.

    The cheap way is to use the -Hprof flags that are there in every JVM. You can have it dump profile data for method times, and even better dump memory profile information which can help detect "stuck" objects (objects that are never collected because you still have a reference to them). I used to use a tool called "HAT" to analyse the results but I'm not sure that's been updated.

    If you're doing J2EE work you can look at a book called "J2EE Performance Tuning". For general tuning (like apps) I'm not really sure what a good book would be, but look around the web for "Java Profiling" and you can find a lot of good material including some cool free tools.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  464. ha ha. by twitter · · Score: 1
    An AC taunts,

    Or, if you're not a developer, can't write code to save your life and really aren't qualified to comment on an article about programming language performance, please say so.

    No, bother, I was right, the article was a troll. The Java server is impressively fast, but C is still faster for most purposes.

    --

    Friends don't help friends install M$ junk.

    1. Re:ha ha. by Anonymous Coward · · Score: 0

      Let's see your code.

  465. Re:Some performance myths by Anonymous Coward · · Score: 0
    I've actually once compiled C code with g++ and it was visibly slower than the same code compiled with gcc ... oh well.

    "once"? I'll take that to mean "a few years ago".

    Try this experiment again, but with GCC 3's g++. I think you'll be pleasantly surprised.

  466. GUIs are far easier to implement in C++ ... by Nicolay77 · · Score: 1

    with wxWidgets than in Java.

    I've used java and wxWidgets, and C++ just rocks with the right libraries around.

    Java has some nice points, like serialization, but in overall, C++ wins, if you know what to use.

    --
    We are Turing O-Machines. The Oracle is out there.
  467. Re:Can I have an infinite budget to write the code by Arroc · · Score: 1

    I agree with you about VB, and this is exactly my point: low learning curve because of simplistic widget concepts != ease of use != better code.

    Examples: Qt is not MVC, take a label or a tree - they don't have data models. Why do I have to use setText on a QLabel, I should be able to just provide something that implements TextModel and let it take care of the text change notifications. The visual and data aspects are very intermixed. I hope I don't have to explain why this is bad. Some people call that a feature and call abstraction "bloat".

    notification mechanism: Last time I checked, QT was using a custom prepocessor for the notification mechanism. I've had many problems in the early days because of more advanced C++ construsts not being compatible. And using C++'s limited features as an excuse doesn't work anymore, check what the Modern C++ design book / Loki library. Even trivial techniques as partial template specialization can help a lot.

    Flexibility: It lacks interfaces. In order to change a behavior sometimes you have to reimplement the entire widget, or at least inherit from the widget. The widget classes are too big, they are doing too many things that they are not supposed to. C++ doesn't have interfaces, but I use classes with only pure virtual functions except the virtual destructor.

    A better GUI toolkit? Swing is one, even maybe JFace. In the C++ world maybe none, I have to give Trolltech credit for being the only ones doing something about the C++ GUI situation. The my GUIisBetterThanMFC argument frankly is not enough.

  468. Re:Can I have an infinite budget to write the code by Arroc · · Score: 1

    I had to buy 5 licenses for a total over 15K. How is that reasonably priced for just a GUI library? In most of the cases you get an complete environment + gui toolkit for free (Eclipse) or a complete environment + gui tookit for less than half the price (M$).

  469. Re:Can I have an infinite budget to write the code by lokedhs · · Score: 1

    Well, it is. Try the latest versions of Java (1.4.2 or 1.5) and you'll notice how much more responsive the app is. Note that JDK 1.5 uses OpenGL for Java2D rendering which makes it a hell of a lot faster.

  470. What about const? by ufnoise · · Score: 1
    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.

    In C++, isn't using const a hint to the compiler that the programmer doesn't expect the value to change. For example:

    const char * p // The data pointed to is constant

    int * const p // The pointer must always point to the same address

    const int i = x*y; // i cannot change it's value

    I am really curious if the use of const could help the situation you describe.

    1. Re:What about const? by ufnoise · · Score: 1
      Just as a followup, the use of const gcc and Sun CC will not even allow this to compile:

      const double x=5; double *p =

      Results in g++ as

      cannot convert `const double *' to `double *' in initialization

      So the compiler knows that the data cannot change and hopefully make some optimizations (e.g. use a register instead of a memory location).

    2. Re:What about const? by jfengel · · Score: 1

      This is true, and many good C compilers will take advantage of it.

      Unfortunately, it only takes one non-const char* declaration to point anywhere in memory. Certain programs will use fancy tricks like putting non-const char arrays in the middle of a structure, and using a pointer to that to modify arbitrary parts of a structure. It's not entirely wise, and it's sure as hell not portable, but "portable" was not the goal of the C semantics.

      So while a smart compiler can do such things, it can be hard while guaranteeing the same behavior as an unoptimized program.

  471. correction. by ufnoise · · Score: 1
    Sorry, html doesn't like amperstands:

    const double x=5;

    double *p = &x;

  472. Re:my arse by Anonymous Coward · · Score: 0

    But really, the question here is whether a generic run-time profiling algorithm can outperform a human with time on his (or her) hands and a good profiler.

    No, it isn't. Not really. Well, at least unless you want to limit the test to this kind of stupid benchmarks instead of real-world situations.

    The question is whether there are enough humans proficient in optimizing that have time on their hands.

    To which answer is obviously NO.