Optimization for free

Discussion in 'Game Development (Technical)' started by princec, Jan 30, 2006.

Thread Status:
Not open for further replies.
  1. StGabriel

    Original Member

    Joined:
    Jan 27, 2006
    Messages:
    26
    Likes Received:
    0
    Ok ... for what's worth:
    I'm an academic turned game programmer. I've written a C compiler and multiple Scheme compilers. I've programmed large programs (1,000 lines) in C, C++, Java, Scheme, Haskell, Pascal, BASIC and Actionscript (Flash). I've also programmed to a lesser extent with Fortran, ML, Python and a few flavors of assembly. I've done things like study the type safety proofs for Java -- both the language and the JVM. I've had many an argument with people doing performance sensitive work in Java, C, C++ and Fortran.

    Oh, and I make a living programming Java (J2ME) games and I actually do like Java as a language.

    That said, it saddens me to see so much blind support for Java. A lot of the Java proponents seem to think that just because you program Java a certain way, that things like memory allocation are efficient or that RTTI is somehow "free". Nope. Uh uh.

    Java is a nice OO language, but it IS inefficient. Most of the things that it seems like you "get for free" do have a cost. Comparing results on loop/array intensive code it is common to have Java code run at 1/10th to 1/5th the speed of similar C code and the memory footprint, beyond loading the JVM, is amost always going to be much larger. Since I don't have these benchmarks on me at the moment I'll just refer you to the win32 language shootout:

    http://dada.perl.it/shootout/java.html
    http://dada.perl.it/shootout/vc.html

    Java is a good language for the things it is designed to do. Performance just doesn't happen to be the primary goal of Java. It is an afterthought. A lot of research has gone into how to get acceptable performance out of Java and it still is quite a bit off the mark of C/C++. Meanwhile, garbage collection, type safety, security and other features of java are very nice things.

    To echo some of the thoughts of Fabio: I too have seen a lot of poor programmers come out of learning programming from Java only. Just like the link he posted indicates, it's not that there aren't good programmers that learned how to program with Java, it's just harder to find them among lots of poor programmers. Java holds your hand a lot and to learn Java you don't have to understand a lot about what goes on under the hood. That has its place. Not everyone wants to be the end-all of programming. But I think that those who do will be very well served by learning a low-level language such as C or by learning a higher level language or language with greater abstractive power like ML, Haskell, Lisp or Scheme. WYSIWYG programming can be powerful but when it is an excuse to not understand what your program is doing it can get in the way of becoming a good programmer.

    Not all games need a lot of power under the hood. Right now with my freetime I am making casual games in Flash, a language I consider to have a lot more performance issues than Java. But a lot of games do need that power. And when you need to get every ounce of performance or keep your minimum specs as low as possible you'r going to have to program in C.

    Use the right tool for the right job.

    As far as efficiency of programming, I know Java and C both very, very well and I can program efficiently with either. Sometimes Java has a feature that is particularly useful and often C does. Java allows quick abstraction but is often lacking the power and control I want to do something. C gives me that control which at times can let me take rather large shortcuts but also gives me more room to "shoot myself in the foot". If I need an abstraction in C like some of the things that Java or Haskell allow me I just build it myself. Function pointers are fabulous creatures if you learn how to use them. It took me a while to get to where I'm at as a C programmer but I also consider myself a much better programmer, even when using Java, for having learned C. I also learned a lot from going the other direction and programming with Scheme and Haskell.

    So my conclusion is that neither programming language is better. They just have different strengths and weaknesses. One of Java's weaknesses IS performance and it is foolishness to assume that just because you don't even have the option to do some of the optimizations that C/C++ are capable of that you aren't losing any performance because of the issues that require those optimizations in the first place. And I also think that anyone who wants to be a good programmer will be well-served by learning as much as they can about all the programming languages that are available to them.
     
  2. oNyx

    Original Member

    Joined:
    Jul 26, 2004
    Messages:
    1,212
    Likes Received:
    0
    The used vm is dated and there is no warm up. It doesnt tell you anything.

    edit: something more recent:
    http://www.idiom.com/~zilla/Computer/javaCbenchmark.html

    http://kano.net/javabench/
    (with the fancy title "The Java is Faster than C++ and C++ Sucks Unbiased Benchmark" ;))
     
    #182 oNyx, Feb 4, 2006
    Last edited: Feb 4, 2006
  3. Vorax

    Original Member

    Joined:
    Jan 21, 2005
    Messages:
    349
    Likes Received:
    0
    First, I would hardly consider 1000 lines of code large, 100,000 lines perhaps.

    J2ME is the bane of Java, it's slow slow...slow.


    We are not blindly supporting Java, we have come to the conclusion after years of using other technologies (I did Assember over 20 years ago for 2 years and did C/C++ for 9 years).

    Ok, if you want to haul out some numbers (I knew it would come to this eventually in this thread ;))...

    Those benchmarks are showing results using Java 1.4.1. Virtually no one uses anything below 1.4.2 because of the performance improvements in 1.4.2 and above.

    Try running those numbers with Java 1.5 or better still Java 1.6 beta. Generally 1.6 beta operates 40-60% faster then 1.5. 1.5 is 30-50% faster then 1.4.1

    The gap is MUCH smaller then you seem to think, especially for things like game development.

    Sun benchmarks Java's performance for game development using an application called Jake 2 - It's a port of the Quake 2 engine in Java.

    These are modern benchmarks comparing Java to C (post Java 1.4.1). Compare the numbers...note that Java is actually producing HIGHER FPS in some cases then C and in all cases is fairly comperable.

    The reason Sun likes to use this program as a benchmark is because it's developed by a 3rd party, and it's the Quake 2 it's an old engine, ie: it's CPU constrained.

    I do think C should be manditory for the reasons you state. That said, I know dozens of excellent Java programmers personally. At least 10 of them work for me in my day job.

    Again...see benchmarks above.

    Also, see games like: Tribal trouble - It's pure Java, it's 3D, it runs at 40 FPS on a 500Mhz PC with a Geoforce 2 video card.

    Java WAS slow...past tense. The performance improvements have brought it to the level where you could the write Doom 3 in it if you desired.

    The Java game I am working on gets over 150FPS in this screen shot at 1024x768 on a AMD 3.2 Ghz computer with a Geoforce 5500... On my work computer that screen gets over 600 FPS at the same resolution with a 3.4 Ghz machine with a Radeon X800XL. 150 FPS compared to 600 FPS...if you know 3D graphics, that's a tell tell sign that it's Fill rate limited, not CPU limited. Which means Java is doing more then fine. Had i been targeting computers with newer video cards, I could unload TONS of stuff to shaders for even more performance.

    Here is a shot I just snapped of a level I am building. It's untextured, but the modeling work is done. You will notice the FPS is at 213 (windowed, 800x600, my home PC - Geo5500, 2.1Ghz, AMD 2600), but below that are two important numbers:

    Rendering: 94
    CPU: 6

    Those numbers are showing how much of the time it takes to render a single frame was used by the video card, and how much by the CPU. 6% is Java, 94% is my video card. During intensive play, the CPU will rise up as far as 12% on my computer, but the bottleneck is ALWAYS the video card, by a large margin. Java is plenty fast. (PS I wrote the engine and I am no John Carmack, there is plenty that could be optimized still)


    I hate to sound like a broken record, but you are really stressing Java's poor performance but quite frankly your wrong about it. The bulk of your argument is composed based on that premise.

    I have nothing against C/C++, loved using them for years. If someone wants to use them, so be it. The only point I ever made in this long exahausted thread is that Java is a viable option for games development and the advantages of a managed language and robust API's can help speed up development.

    edited: For grammer and some additional points
     
    #183 Vorax, Feb 4, 2006
    Last edited: Feb 4, 2006
  4. StGabriel

    Original Member

    Joined:
    Jan 27, 2006
    Messages:
    26
    Likes Received:
    0
    You're right, I linked to the old shootout.

    http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=gcc&lang2=java

    Java performance is still subpar even if it can predict array bounds for a lot of cases, etc., now. I've run tests with 1.42. I wasn't claiming J2ME to be representative of performance but it is representative of language style. Some 3d games will run ok on Java, but they will tend to be a generations or two behind similar games written in C (your examples are in this category). If Java has enough horsepower for you want, great. You'll still have a significant increase in power and more control with C.

    Anytime a language or runtime tool optimizes for you, you are losing control. You are never getting optimizations for free. Sometimes those optimizations can be pretty good or even better than you might hand code. In a lot of cases, however, you can still do a lot better when you control the code yourself. Myself -- I am comfortable enough with C that the gains from Java are minimal. They are there and in certain contexts I prefer Java, but in a lot of other contexts I can program just as quickly in C, rolling my own interfaces, objects, etc., as needed.
     
  5. Vorax

    Original Member

    Joined:
    Jan 21, 2005
    Messages:
    349
    Likes Received:
    0
    It's BETTER to test with old engines because they are CPU constrained. (the graphics were designed for 1998 cards in the case of Q2).

    If Java can perform on par with C on an old engine then it can perform on par in a new engine. In any high-end game engine, the goal is to have the Video card be the bottleneck, not the CPU. How do you think Halo 2 could be written on the XBox? It's a substandard CPU, but it's got a nice video card in it (Geoforce 4ti).

    If my engine gets 600FPS on a modern video card without using the cards true capabilities, then I could add at least 10X more work to either the CPU or the video card, or 5x more work to both and still get 60FPS. That would be in the Doom 3 (modern engine) quality range now and all in Java.

    Agreed, but Java is fast enough for a modern engine, so the need is greatly minimized. The video cards are the bottlneck, not the CPU.

    Then why are you writing in Flash and J2ME?

    PS: Those benchmarks don't even say what Java, and when I hauled up 1.4 server ...what version of 1.4??....the .2 is VERY imporant and as I said, 1.5 is much faster again...and 1.6 still faster again then 1.5 (significantly so).
     
    #185 Vorax, Feb 4, 2006
    Last edited: Feb 4, 2006
  6. soniCron

    Indie Author

    Joined:
    May 4, 2005
    Messages:
    3,664
    Likes Received:
    0
    Hmm. That's kinda silly logic.
     
  7. Vorax

    Original Member

    Joined:
    Jan 21, 2005
    Messages:
    349
    Likes Received:
    0
    Why? The card is practically laughing at the work I am putting on it, and so is the CPU. That and I am not using shaders. PS: nor am I denting the VRam, nor using modern extensions (OGL 1.4 or above)... I can practically hear the card snoring running my little game ;)
     
  8. oNyx

    Original Member

    Joined:
    Jul 26, 2004
    Messages:
    1,212
    Likes Received:
    0
    Also useless. One version is 1.4.whatever and no idea what the other one might be. It also doesnt look like they took startup time into account.

    "Each program was run once pre-test to reduce cache effects. Program output is redirected to a log-file and compared to the expected output.

    Each program was then run 3 times with program output redirected to /dev/null. We show the lowest measured CPU time and the highest memory usage, from the 3 runs."


    Without warmup you're benching the wrong thing. Its not like your game only runs for a few seconds, right?

    Try to find one with 1.5 server or 1.6 client (about the speed as 1.5 server). Bonus points for opteron systems.

    edit:
    I ran scimark2 just for the fun of it.

    Results:
    Code:
                               gcc      java
    Composite Score:           43.57    53.33
    FFT             Mflops:    25.08    25.20
    SOR             Mflops:    83.81   110.29
    MonteCarlo:     Mflops:    12.10     9.88
    Sparse matmult  Mflops:    36.85    46.22
    LU              Mflops:    60.01    75.05
    
    gcc: 3.4.2
    java: 1.5.0_05 (client)
    Someone else's results:
    Code:
    CPU @ 1.8GHz, RAM @ 2-3-2-5, 1T, DDR400
                                      <- 1.5.0_04 ->     <- 1.6.0-rc-b60 ->   VC++ 6
    SciMark 2.0a                      client  server       client   server
    Composite Score                   221     369          315      391          177
    FFT (1024)                        107     289          276      364          109
    SOR (100x100)                     424     591          433      585          387
    Monte Carlo                        39     79            66      110           41
    Sparse matmult (N=1000, nz=5000)  200     236          361      210          168
    LU (100x100)                      333     650          442      687          182
    Interesting isnt it? ;)
     
    #188 oNyx, Feb 4, 2006
    Last edited: Feb 4, 2006
  9. Fabio

    Original Member

    Joined:
    Sep 30, 2005
    Messages:
    499
    Likes Received:
    0
    No, not interesting at all. First of all, it is biased towards Java. I had bet they use the same sources with only minimal changes for both platforms (C and Java), I checked and my fears were right. The C sources simply aren't optimized for the many possibilities C gives you. They're simply a sintactical 1:1 conversion from a Java-tuned source to an alien, lame, stupid and senseless C implementation of the same.

    Hell, they even admit it at the top of the C source page:
    and then add:
    This is simply laughable. It's like pretending to compare a bycycle and a Ferrari F50 by removing 2 wheels from the latter and putting it in the bathroom like the former. Now if that's a way to reach a "fair" comparison..

    A practical example, instead: how would you reverse a string of bytes, a byteplane (for gfx applications such as mirroring)?

    Now write a Java source to do it, make it as fast as Java allows, translate it 1:1 to C or C++ and benchmark. I would be surprised to see any big difference from two compiled languages.

    But what you really don't want to understand is that in C and C++ you can do alternative things that a "fair" comparison between Java and C or C++ using the same identical algorithm (even worse, Java-tuned) will never allow.

    Can you inline the BSWAP instruction in Java? That alone with some clever loop unrolling will make the reverse example of above *10* times faster than the fastest Java source "mathematically possible", ever, even written by Java God in person. Then if you like to translate 1:1 that Java source to C or C++ to prove that they have similar speeds, do it if it pleases you, but it's not the C++ coding I and most other C/C++ programmers have in mind and do every day.

    Also, benchmarks are notorious for being criminal. The one you mentioned (which says "[SIZE=+1]How fast is your Java platform for number crunching?"[/SIZE].. it's clearly unbiased, is it?) uses the same sources (thus Java style programming) on both environments (take a look at it (scimark2c.zip), THEY DON'T EVEN USE POINTERS IN A USEFUL WAY!! IN A C SOURCE!! SHAME!!), doesn't even tell you the compiler options that were used, probably++ unoptimized code (and gcc is famous for producing bad code even when all optimizations are turned on). Come on..

    Now you call that interesting???

    :D

    Write the string reverse function, please. If you do I'll do the same in C++, C and Asm and then let's run them, benchmark something tuned for each language (instead of a Ferrari F50 with two wheels contrained in a bathroom, shame!) and let's laugh once and for all.

    Real programming is another thing than BASIC or Java, sorry, no matter how much artificial evidence you try to bring.

    If you were right, I would be the first to switch to the mighty Java. But it's just not like you say, although the illusion exists when one writes bad code (because bad code runs slow on any platform). Mirror those bytes FAST, please.. and let's see.

    What a waste of time dealing with kids.. dammit.

    REPEAT #16
    MOV EAX,[ESI]
    SUB ESI,4
    BSWAP EAX
    MOV [EDI],EAX
    ADD EDI,4
    END_REPEAT

    even the above UNOPTIMIZED (believe it or not, there are tens of tricks to make it *much* faster, but I'm afraid you then wouldn't even be able to read it) piece of main loop in Asm that you can flawlessly inline/integrate in C or C++ will be tens, maybe hundreds times faster than the fastest ever possible Java compiled implementation: and the fact that you then pretend that C is not much faster than Java, by compiling with gcc (bleah!) without optimizations the same piece of Java crap, doesn't change reality a tiny bit.

    Why don't you stop making a fool of yourself and give up this stupid cause of "Java is faster than real coding"???

    Write that byte string reverser, come on. Or get serious, finally, once and for all.
     
  10. Fabio

    Original Member

    Joined:
    Sep 30, 2005
    Messages:
    499
    Likes Received:
    0
    This page is certainly more interesting and more fair than yours:

    http://www.w3sys.com/pages.meta/benchmarks.html

    and this one too:

    http://www.freewebs.com/godaves/javabench_revisited/

    Now can we close this stupid, useless thread please? Properly designed Java code will never be faster than properly designed C or C++ simply because Java wasn't designed with that goal in mind, it has certainly many other qualities, but it will NEVER be faster (with real code, no stupid benchmarks made ad hoc to demonstrate that Java is faster than Java code 1:1 translated to C), simply because, whatever are the efforts, the infrastructure and architecture of Java doesn't allow it. And there's nothing bad in it, what is bad is not wanting to accept a simple and more than evident reality.

    Use whatever you like, but don't insult the simple reality of things. You would do no good to your intelligence.

    Also, the fact that the world uses Java won't harm us lowlevel programmers, the real opposite. So don't worry about our business, we know what's good for us in the end. Or go bother John Carmack and waste HIS time, but let's close this stupid thread please because it's over and over.
     
    #190 Fabio, Feb 4, 2006
    Last edited: Feb 4, 2006
  11. oNyx

    Original Member

    Joined:
    Jul 26, 2004
    Messages:
    1,212
    Likes Received:
    0
    Haha.

    "the fact that you then pretend that C is not much faster than Java"

    Read the results again (bigger=better). Java won there (except for three results with the 1.5 client vm).

    But its nice to see how pissed off and irritated you are. Multiple exclaimation marks, bold, uppercase and even big fonts... heh :)

    Feel free to rewrite the C stuff. Would be interesting to see how much time you spend with that and how much you actually gained. It would be also interesting to see that in comparsion to 1.6 client/server.

    No matter how you look at it the benchmark does at least show that straight unoptimized java code runs way faster than its C counterpart.
     
  12. Fabio

    Original Member

    Joined:
    Sep 30, 2005
    Messages:
    499
    Likes Received:
    0
    You're right, I am pissed whenever I waste my precious time with obtuse kids that pollute the-board-I-care-of with stupid and dangerous misinformation.

    But enough evidence was brought to make your "argumentations" look at least one tenth as fool as they deserve, so I'm done. :D
     
  13. Vorax

    Original Member

    Joined:
    Jan 21, 2005
    Messages:
    349
    Likes Received:
    0
    Fabio - Calling people kids is a uncalled for, we are adults here, please try to act as such.

    Anyway - As you know, that's not C - it's assembly. We have been talking about Java vs C/C++ - None one said java was as fast as assembly.

    However, since you brought it up a; you do realize a java program can call C or assembly routines, right? (just like your example) Ever wonder how our games are talking to OpenGL? If you did know, what's your point? The only performance advantage C has in that regard is the assembly can be inlined. See JNI for more detail if your interested.
     
  14. Fabio

    Original Member

    Joined:
    Sep 30, 2005
    Messages:
    499
    Likes Received:
    0
    Hi Vorax,
    I don't see what's wrong in using Java or any other language.

    The only thing I'm opposing to is the (deliberate or not) lies that Java is faster than C. This is impossible given the nature of the two languages. There are many reasons listed here (written by a Java advocator, but at least he is a rational, objective person) that show, with every evidence, that the architecture of Java simply can't come to par to the one of C++ when it comes to speed. Comparing a properly written Java source compiled with a great Java compiler with a unproperly written C source compiled with a bad, unoptimized C compiler doesn't make justice to Java, nor to the intelligence of any of us. Java architecture just can't come par to C++, and in all but the most trivial things this shows up very easily. Benchmarks have never represented reality, those written with false intents as analyzed here and here represent reality even less. No pretestuous argument can change that Java speed just can't come par to C++, it's more than evident in its architecture, simple as that.
    Which is not a bad thing at all, Java was born for other reasons than speed and it's impressive the quality of its compilers, but there's a limit to all of this, and pretending that on a fair, honest comparison Java can be as fast as C++ (let away faster than C) is an insult to the intelligence of many people here.

    That's all, for me at least.

    Being productive means expecially not wasting too much time on a thread like this (and many many times I refrained from joining such discussions in the past, this is actually the very first time that I do), and the time wasted on this thread is no justification for saying that a language is more productive than another. It is in contraddiction with that principle, too.
     
  15. Dom

    Dom
    Original Member

    Joined:
    Aug 5, 2004
    Messages:
    116
    Likes Received:
    0
    I use both Java & C, Java for web games and C for download games.

    Now on a theoretical side, Java is (if anything) the way forward. Think of not in terms of previous implementations - but in theory -> Java bytecode is little more than the intermediate code of a C compiler. Imaging your C compile would stop 1/2 way andthen do the final step on the target machine. Wouldnt that be cool? I know my VC has to use the processor model 'blended' as my C code has to target any pentium series, but the Java one doesn't. The final optimisation CAN be done with a single processor & architecture in mind, and so CAN produce more optimal code.

    BUT:
    1) Close to 75% of our visitors to our website (we easily get over 10,000+ a day) DO NOT have the latest Java, & refuse to install it. 25% dont have ANY Java, and the other 50% use Java 1.1 or 1.3, and nothing you will say can get them to change.
    Why? I dont know. This drives me up the wall as Im stuck using 1.1 for webgames, and yes, 1.1 is slow and nasty.
    Compared this to Flash - with a near 95% of computer have Flash. This is a problem for Sun's marketing, as well as the technical installation side - we get an email a day from someone new who has instaled the latest version only to find the install is bugged & Java has stopped working.
    This is important and the simple commercial pressure of 25% vs 75% means that domestic JAva use on the web is still stuck in the stone age.

    2) Java Language features. There are some simple things that C can do that Java cannot do. Dare I say it - pointers is one of them. Reading a float as an int. Unsigned integer maths. #defines. This is a huge loss in programmer power from C is the the largest cause of lost productivity when I write a web game in Java vs. a download game in C.
    On the other hand, people have found that the lack of pointers makes them write less buggy code faster. Its a personal thing. At the end of the day use whichever you are most comfortable with using.

    This RTTI business. It is implemented almost exactly the same in Java & C. Checking the type involves 2 memory reads and a compare. The cost in C is trivial, but even that cost can be removed. The cost in Java is trivial, but it cant be removed.
    If your game/app is time dependant due to the use of RTTI then you have serious issues that neither Java or C can help you with.

    So in summary - The idea of Java is fantastic.
    The current execution is ok if you can cross the VM installation hurdle.
    All else is of the level of a religeous discusssion - use whatever you like best.
     
  16. Fabio

    Original Member

    Joined:
    Sep 30, 2005
    Messages:
    499
    Likes Received:
    0
    Mind you, also C/C++ code can be compiled for various targets, optimized for them, and I don't know any single platform where there isn't available a C compiler.
    Moreover, for some serious (scientifical or not) processing, you get SIMD (either inlined Asm or a C/C++ capable of producing vector code, like MS VC 2005 for example), which is another clear advantage to speed, let away all the architectural ones (like, just to make an example, in C++ you can remove the overhead of virtual functions in case you don't use them anyway, in Java you cannot.. and there are tons of other similar examples which could be made, check here for a list).

    I agree with all the other things you wrote anyway.
     
  17. oNyx

    Original Member

    Joined:
    Jul 26, 2004
    Messages:
    1,212
    Likes Received:
    0
    Dated. (Last updated: Saturday, April 01, 2000)

    Oh noes! Interpreted java is slow! Talk about the news flash! :p
     
  18. Fabio

    Original Member

    Joined:
    Sep 30, 2005
    Messages:
    499
    Likes Received:
    0
    You want more?

    oNyx, you've really got a perverse passion to ignore evidence (like those other two links, which are updated, and which demonstrate beyond every evidence how false are those benchmarks), and the best you come with is saying that the other link is dated 2000.

    But that document was mentioned because it compares the ARCHITECTUREs of both languages, thus THE DATE IS MEANINGLESS, unless these differences changed, which didn't happen. So what the hell do you want to demonstrate??? Nothing, as always, you've just to add noise to the signal.

    I will make some examples now (taken from that same document, dated 2000, that you cannot even read and interpret correctly):

    There are no unions in Java. Unions are the key for a lot of important optimizations and possibilities in C and C++. Hell, I even find C and C++ too limited in this regard! Can you tell me how having less features, i.e. give the programmer less possibilities, would result in faster execution code? Care to explain? Care to explain also if this changed since the year 2000? So why did you bring, as your sole argument, the fact that the document was dated 2000? Do you understand the matter we're talking about here? Do you understand that you cannot benchmark Java without unions and C without unions and call it a fair benchmark?

    How can a limitation result in faster code? Conditional expressions using non booleans are a very common trick in C/C++ which is often handy and improves not only execution speed, but also development time. How having less features, give the programmer less possibilities, could ever result in faster execution code? Care to explain also if this changed since the year 2000?

    Look, in C++ chars take half memory size and string manipulation is in general PLENTY more efficient than in Java. Yes, we can use Unicode too, and very easily. How is it possible that enforcing Unicode results in faster execution code? Care to explain? Care to explain also if this changed since the year 2000? Do you know how much inefficient is text handling in Java? Do you know that strings are a good benchmark for the efficiency of a language? (one of the reasons why I still prefer C over C++ in some fields).

    Wow.. a literal becomes a run-time object! How inefficient! You should duck!

    Abusing the heap when stack allocation would be possible is another big waste, architecturally speaking. But I know the internals of the Java VM to already know why they did so, because the stack is so limited. Now tell me how a limitation (heap must be abused much more than in C/C++) can possibly result in faster code? In Asm, when I need storage, I don't even allocate it. I directly write to an offset of ESP. That's lightspeed, and requires some tweaking of the TIB to run (FS: segment). Now this is what I call fast allocation/deallocation of memory, and is one of the reason why I use naked C/C++ functions sometimes (but anyway even not resorting to such tricks, the C/C++ stack model is way faster than the Java one).

    I initialize pointers and variables in C/C++ only when needed, otherwise it's only an unnecessary overhead. The compiler will take care to tell me "warning, variable x used without having been initialized" in case it's read before any write. And that's all that is really necessary, to avoid bugs. Java places this overhead always, and thus you say that it is "optimized for free"? :D

    Poor kid programmers! Let's protect them or they will get hurt with their own hands! This has touched me so much inside that I nearly cried. :rolleyes:
    Maybe it is because I come from an Asm background, but I never had any single bug from pointers or memory leak I can recall of. If I allocate memory, the first thing that instinctively I have to do is free it. Then I built the code inside. Pointers? If you can master them, they're a great tool. If you can't master them, this will come to a surprise for you, but you can avoid to use them even in C/C++! So you're safe, boy! Do you understand that you cannot benchmark Java without pointers and C without pointers and call it a fair benchmark?

    Like to say, when you'll write (if ever) some serious code the GC will shoot at your feet. If you feel the need for a GC (but why?? personally I've never felt this need, maybe I don't write buggy code, or don't like useless features), you can add one in C++ very easily, mind you. So, again, Java enforces overhead, and you call this "free optimization"! LOL.

    so C++ gives you an option, that you're free not to use if it scares you (poor programmer!), this option will make your program faster where applicable (actually, in a lot of real world cases). Period. Java doesn't give you this option. How can it be faster than C++? Care to explain us please? Or you want to insist with your nonsense? Care to explain also if the date 2000 has any meaning? Is today (2006) this architectural thing changed???
    Also, to run a benchmark where Java must use (because of its architecture) virtual functions everywhere, and you enforce C++ to use them even when they're unnecessary (something no decent C++ programmer would ever do), and then pretend that Java is "optimized for free" and both language when compiled perform similarly is an insult to the intelligence of any real programmer. Do you understand this simple thing? Have you read those other two links, which are certainly not dated 2000, that explain how all those "Java is faster than C" benchmarks are bogus?

    Which is like to say "for simple code, Java and C++ are roughly equivalent in this regard. For complex code, with Java you will get in trouble sometime, hey, but not every day anyway!". But Java wasn't designed for complex coding anyway, so that's not a disadvantage (until you start to write some serious code, i.e. probably never, to notice), ain't it? Now care to explain me how having one less feature, option, bag of tricks/tools, can make things run faster? How, in this regard, things changed from 2000 to now? Why did you bring as argument the date 2000? What did you think to prove?

    Why didn't they make all of these stupid, unnecessary for experienced programmers, things optional in Java? Simply because Java was designed from the ground up for weak programmers. Which doesn't mean that all Java programmers are weak, but you get my point anyway: having less possibilities doesn't result in faster code, but can only result in slower one.

    IMHO is so stupid to say "optimizations are free" when in reality you simply LOSE those optimizations. It's ridicolous, and the length of this thread is sad. Also your insistence, based only on noise and zero real, valid arguments.

    Keep on insisting if you want.. but reality won't change a single bit.
     
  19. Savant

    Original Member

    Joined:
    Feb 8, 2005
    Messages:
    1,674
    Likes Received:
    0
    I'm definitely convinced! Your modules must make you insanely productive if you're able to piss this much time away on message boards.
     
  20. Fabio

    Original Member

    Joined:
    Sep 30, 2005
    Messages:
    499
    Likes Received:
    0
Thread Status:
Not open for further replies.

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer