Thread: Speed of C++

  1. #46
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by vart
    And he does not want to wait 3-4 hours till the report will be build (he is not intrested to know what number of Megabytes to be parsed to generate report, he just wants to get the report in minutes, not hours)...
    So what are you saying?
    That on one programming language you can cut that down to minutes while on another it takes hours? Because that's what this is all about. Not performance issues spawned from bad programming, but speed comparison between programming languages.

    so no, I don't have any application to support, where the time issue is not critical... Bad luck?
    No. You are just missing the point of this debate.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  2. #47
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    I'm really not going into the debate of which is faster, C++ or Java.
    Your words, not mine.
    No. You are just missing the point of this debate.
    I'm not into debate. Have nothing to say about the issue. And don't want to.

    You said that for most application the time issue is not critical.
    I said - I have no application to support where the time issue is not critical. That's all. I make no futher suggestions, just stated the fact.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #48
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    > That's all. I make no futher suggestions, just stated the fact.

    Fair enough.

    I'm glad to know I'm right when I account for exceptions.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #49
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    A fact that nicely points out the real issue: speed is far more about code design than the language used. If an application that generates a report from some data reads all data in, begins swapping like mad, to generate a report, then the most l33t assembly won't make it even remotely as fast as a program that reads the data incrementally (assuming the report allows that), even if that other program is written in JavaScript or Ruby (the current Ruby implementation is one of the slowest languages in wide use out there).
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #50
    Registered User
    Join Date
    Dec 2006
    Location
    Washington
    Posts
    18
    Quote Originally Posted by Laserve
    Oh my its decided! java is slower!



    What do *you* think you're actually testing here? this is nothing more than a I/O system test of 1 java and c++ implementation.

    And then, this just shows that you are a mediocre java programmer:

    For instance, have you any idea what this line is doing?

    System.out.println( i + " is an even number! " );

    You're using way more objects and dynamic memory allocations than is necessary. Those not needed 1000 objects may trigger a garbage collection sweep which will of course make you app slower.
    Try rewriting it with StringBuffer and Stringbuffer.append and give the results again
    Get Stuffed! Don't try to act like I don't know what is happening "behind the scenes" simply because I used it in the manner shown in my "test." I started programming in Java with JDK v.71 on Solaris before it was supported on any other platforms. Did you happen to notice that I also wrote it without any output? C++ is still way faster. Some would argue due to the JVM startup time. I don't care why, C++ and Java side by side, C++ will always be faster.

    Having discussed, at length, the thinking and activities that went into the creation of the Java programming language with James Gosling, I can say for sure that it wasn't ever meant to be a "better C++" as was offered by CornedBee. In fact, Gosling told me that the "best aspects of many" languages were borrowed from for the creation of Java, which was in response to my observerations of how Objective C-like it was in terms of GC, "import" vs include, "mother-of-all-objects" and single inheritance/interfaces.

    So, the bottom line is Java is for those who can't program in C++!

    As for being a mediocre Java programmer, at least I know that Java is capitalized!

    ...but, since you're the expert Java programmer and I'm simply mediocre, maybe you'll realize that there isn't even a need for a StringBuffer and the append call?!

    Code:
    final class even_numbers
    {
        public static void main( String[] args )
        {
            for( int i = 0; i < 1000; i++ )
            {
                if( i % 2 == 0 )
                {
                    //System.out.println( i + " is an even number! " );
                    System.out.print( i );
                    System.out.println( " is an even number! " );
                }
            }
        }
    };
    
    real    0m0.185s
    user    0m0.135s
    sys     0m0.034s
    
    C++
    real    0m0.017s
    user    0m0.002s
    sys     0m0.002s
    
    Java using StringBuffer (not printing the contents of the SB)
    real    0m0.138s
    user    0m0.082s
    sys     0m0.018s
    
    Java using StringBuffer (printing the contents of the SB)
    real    0m0.189s
    user    0m0.134s
    sys     0m0.024s
    Java is a DOG WITH FLEAS...if you need speed, you need C!

    And, since you're the world's gift to Java, maybe you'd be happy to learn that the JDK documentation recommends using StringBuilder over StringBuffer in single threaded applications. I'll quote the JDK documentation:

    "Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations."


    :davis:

  6. #51
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Why do you keep posting stats about 1000 iterations of nothing? Do you honestly think that measures something meaningfull? You said yourself that your example was trivial, yet you still quote your results. The fact that the example is pointless nullifies any result you obtain.

  7. #52
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    > In fact, Gosling told me

    He didn't tell you enough.

    > Java is a DOG WITH FLEAS...if you need speed, you need C!

    If you need speed you need a better computer. Meanwhile you haven't been listening...
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #53
    Registered User
    Join Date
    Dec 2006
    Location
    Washington
    Posts
    18
    Quote Originally Posted by Perspective
    Why do you keep posting stats about 1000 iterations of nothing? Do you honestly think that measures something meaningfull? You said yourself that your example was trivial, yet you still quote your results. The fact that the example is pointless nullifies any result you obtain.
    Hopefully you've obtained 2nd grade and realize that meaningful doesn't have two "L"s, but obviously, that is a waste of everyone's time here...

    The example shows that for the same code in C++ versus Java, that C++ is faster. Show me the same code in Java that is faster than in C++ or STFU.


    :davis:

  9. #54
    Registered User
    Join Date
    Jan 2007
    Posts
    8
    It's a bad comparison, C++ has had 5+ more years of optimazation and the compiler optimazation changes from year to year are starting to slow down; Java on the other hand is actively getting faster in its implementations. So I think the choice of which to use should depend on other factors (I personaly don't use Java because I use FreeBSD and it used to always be a .......... to install the JVM, so I am kinda biased). So instead of focusing on the current speeds, look instead at the projected speeds, in the near future (due to it becoming open source) I think Java implementations are going to become near the speed of C++.

  10. #55
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    Quote Originally Posted by :davis:
    Hopefully you've obtained 2nd grade and realize that meaningful doesn't have two "L"s, but obviously, that is a waste of everyone's time here...
    Because (and I think this is the second time I've said this to you), this isn't a place where we critique every detail of everyones English. I'm almost certain that the main subject of this board is programming, unless you know about a hidden section that focuses on being extremely anal about the English language.
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  11. #56
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    > Hopefully you've obtained 2nd grade and realized that meaningful doesn't have two "L"s, but obviously, that is a waste of everyone's time here...

    same goes to you.

    > The example shows that for the same code in C++ versus Java, that C++ is faster. Show me the same code in Java that is faster than in C++ or STFU.

    Why? Do you think you made a point with your pathetic little example?
    "Look C++ is faster than Java because of these 10 lines of code". Do you even realize how ridiculous your whole argument is?
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  12. #57
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Write something significant and come back to us, perhaps if it were to... do something?

    Or better yet, get an open mind, other languages exist and prosper for a reason, even if you don't like it. You can always just never let Java code execute on your computer and feel your leetness with all the speed.

    EDIT: Wow :davis: you got some balls, telling professionals to 'STFU' 'cause C++ executes a bit faster (which would become trivial in scaled examples.)
    Last edited by Wraithan; 01-10-2007 at 09:10 PM.

  13. #58
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    C++ is still way faster. Some would argue due to the JVM startup time. I don't care why, C++ and Java side by side, C++ will always be faster.
    Well, you have used a specific example in an attempt to prove a universal statement, so your statement remains unproven. Even if you did manage to prove it, as pointed out by others in this thread, your conclusion only matters in some cases.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #59
    Insane Game Developer Nodtveidt's Avatar
    Join Date
    Nov 2006
    Location
    Isabela, PR
    Posts
    105
    I wasn't aware one could obtain 2nd grade...where do you put it once you've obtained it?



    Anyways, I think the only place Java is going to excel consistently is on Java-based cellphones...
    Code:
    cout << "Language comparisons are dumb";
    echo("Language comparisons are dumb");
    PRINT "Language comparisons are dumb"
    alert ("Language comparisons are dumb")

  15. #60
    Registered User
    Join Date
    Jun 2004
    Posts
    201
    Next time try and write your godly code at the first attempt then
    The timings already went from 0.313 to 0.138 which is 3 times as fast on such a stupid example

    Quote Originally Posted by :davis:

    Old example from first page
    real 0m0.313s
    user 0m0.138s
    sys 0m0.030s

    Java using StringBuffer (not printing the contents of the SB)
    real 0m0.138s
    user 0m0.082s
    sys 0m0.018s
    I cant believe you keep defending this stupid example when you're the lord of the java code

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I am very new . . . :(
    By Eternalglory47 in forum C++ Programming
    Replies: 6
    Last Post: 09-05-2008, 11:29 AM
  2. Flight Simulator Wind Speed!!
    By Dilmerv in forum C++ Programming
    Replies: 6
    Last Post: 03-20-2006, 12:40 AM
  3. Replies: 6
    Last Post: 01-08-2006, 02:49 PM
  4. increased net speed
    By PING in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-29-2005, 07:05 AM
  5. Questions on Speed of Execution
    By wavering in forum C Programming
    Replies: 22
    Last Post: 01-20-2002, 02:04 PM