Java's performance far better that optimized C++

Discussion in 'C++' started by Gaurav, Jun 16, 2004.

  1. Gaurav

    Gaurav Guest

    Gaurav, Jun 16, 2004
    #1
    1. Advertising

  2. "Gaurav" <> schrieb im Newsbeitrag
    news:...
    > http://www.sys-con.com/story/print.cfm?storyid=45250
    >
    > Any comments?
    >
    > Thanks
    > Gaurav


    Huhuhu-hahaha...
    Java faster ...haha... than C++ ...ha-hahaha...

    First of. If you take a close look at the language features you will
    see that you can do everything you do in Java in C++ but not vice
    versa. Next, if you "optimize" code by the compiler it can't become
    any better than the crappy C++ you provide. So, if you want to really
    compare the 2, you should get 2 professional prograamers for each
    language and let each one do the way their language requires doing.
    Next, gcc 3.3 is not really a good optimizing compiler. Better than
    2.95, but not as good as say the intel or the codewarrior compilers.
    But for a wednesday mornig, a good joke, thank you.

    -Gernot
    Gernot Frisch, Jun 16, 2004
    #2
    1. Advertising

  3. The code in Java cannot be any faster than in C++, because with C++ the
    generated code is practically 100% optimal, provided that the program is
    written with it in mind, and the compiler is good. And there are good
    compilers out there.

    Best regards,
    Marcin
    Marcin Kalicinski, Jun 16, 2004
    #3
  4. Gaurav

    tom_usenet Guest

    On 16 Jun 2004 00:45:02 -0700, (Gaurav) wrote:

    >http://www.sys-con.com/story/print.cfm?storyid=45250
    >
    >Any comments?


    Whenever I look at inter-language benchmarks in detail, I always find
    a flaw in the benchmarking for one language or the other (and often
    both), generally based on the author's bias (they generally have
    greater expertese in one language than the other).

    In the benchmarks you've posted, the compiler options provided to GCC
    are sub-optimal, and no functions seem to have been declared inline.
    For example, many of the tests would benefit from loop unrolling,
    which only happens on -O3 I think. Some of the benchmarks are also
    highly synthetic (they don't really do anything except try to bombard
    a particular language feature in a way that never happens in a real
    program). It's better to set a required output for the input, and then
    let the program achieve that output however it wishes to, balancing
    code clarity with optimization.

    Incidently, I got the fibonacci test down to around 0.1 seconds using
    this simple code:

    unsigned long fib(unsigned long n) {
    unsigned long last = 1;
    unsigned long current = 1;
    for (unsigned long i = 2; i <= n; ++i)
    {
    unsigned long newCurrent = last + current;
    last = current;
    current = newCurrent;
    }
    return current;
    }

    Tom
    --
    C++ FAQ: http://www.parashift.com/c -faq-lite/
    C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
    tom_usenet, Jun 16, 2004
    #4
  5. Daniel Blankensteiner, Jun 16, 2004
    #5
  6. Gaurav wrote:
    > http://www.sys-con.com/story/print.cfm?storyid=45250
    >
    > Any comments?
    >


    Those tests expose one regularity - the examples where OS support is
    extensively used are slower than those where the entire code in
    performed in process space. Performance of the former suffers from
    user/kernel mode switching and if it is done at least once per loop
    iteration the impact must be pretty visible.

    So all C++ examples with extensive heap or stack (function calls) memory
    allocation must be slower than corresponding Java examples where similar
    functionality is performed by the JVM directly in the user process space
    (Fibonacci, hash, object creation).

    Of course if one is ready to pay with slower startup and bigger memory
    consumption then he/she may can have the same in C++ using inlining,
    memory pool and other commonly used techniques.

    When such handicaps are not introduced (nested loop, random numbers) C++
    performs faster as expected.

    One thing surprised me. For the reason described above I expected the
    method call example to be slower in any case in C++ than in Java, then
    after looking at the code it appeared that all member functions were
    coded inline and at least some of them were optimized away by the
    compiler. So this test does not fulfil its goal. The other ones also
    introduce some unnecessary temporary variables etc. and should not be
    used as representative C++ code.


    Regards,
    Janusz
    Janusz Szpilewski, Jun 16, 2004
    #6
  7. "Gaurav" <> wrote in message
    news:...
    > http://www.sys-con.com/story/print.cfm?storyid=45250
    >
    > Any comments?
    >


    I was recently part of a team that rewrote an largish C++ app in Java. No
    question that for this application the Java version was slower than the C++
    version. No doubt the Java version had some advantages (platform
    independence for instance) but it was slower and noticeably so.

    john
    John Harrison, Jun 16, 2004
    #7
  8. Gaurav

    Jorge Rivera Guest

    Gaurav wrote:
    > http://www.sys-con.com/story/print.cfm?storyid=45250
    >
    > Any comments?
    >


    In general, you can find arguments to many unfounded things. Weather
    this is correct (which I doubt) or not is irrelevant most of the time.

    Don't worry about it unless you need to.

    Barely related question.

    How many of you guys actually work on projects in which performance is
    critical? (Something written in Java is unacceptable)

    I see value in both languages, however, it appears as though many people
    immediately dismiss Java, regardless of the scope and requirements of
    the project.

    JLR
    Jorge Rivera, Jun 16, 2004
    #8

  9. > How many of you guys actually work on projects in which performance is
    > critical? (Something written in Java is unacceptable)


    When you write a conventional user application for a multitasking system,
    your program should accomplish its tasks as fast as possible. Therefore, we
    are commited to deliver the fastest software ever. 0.01ms vs. 0.1ms responce
    on user button click is much more important for us as opposed to development
    time. Therefore, we write huge number of code lines and ignore impressing
    IDEs like Intellij Idea and go on wasting our time and writing unreliable
    code in order to deliver the best performance. Slow C++ compiler does lots
    of things for us including and compiling huge files.
    valentin tihomirov, Jun 16, 2004
    #9
  10. Gernot Frisch wrote:

    > ✄
    > you will see that you can do everything you do in Java in C++ but not viceversa.


    So there are something that may be do in C++ and not in Java?
    Interesting...

    Please give me your curriculum, so I can hire you in my company!

    - Dario
    =?UTF-8?B?IkRhcmlvIChkcmlua2luZyBjb++sgGVlIGluIHRo, Jun 16, 2004
    #10

  11. > So there are something that may be do in C++ and not in Java?


    writing an OS ( Kernel ) ?
    Rainer Hausbach, Jun 16, 2004
    #11
  12. Rainer Hausbach wrote:

    >> So there are something that may be do in C++ and not in Java?

    >
    > writing an OS ( Kernel ) ?


    The "Church Thesis" or "Turing-machine-computable" or ...
    .... means anything to you?

    - Dario
    =?UTF-8?B?IkRhcmlvIChkcmlua2luZyBjb++sgGVlIGluIHRo, Jun 16, 2004
    #12
  13. Jorge Rivera wrote:
    > [...]
    > How many of you guys actually work on projects in which performance is
    > critical? (Something written in Java is unacceptable)


    In every application (unless it's a really simple one) there are critical
    parts where performance is paramount. Whether performance takes front
    seat in that case is up to the managers. I've worked on systems where
    performance-critical parts were written in C++ (and the rest in Java) and
    where everything was required to be written in Java (and the performance-
    critical parts were licked out as good as it gets in Java).

    > I see value in both languages, however, it appears as though many people
    > immediately dismiss Java, regardless of the scope and requirements of
    > the project.


    "All generalisations are wrong" -- unknown author. You would have to
    put some numbers showing what you mean by "many". Is 10 out of 100000
    -- many? IOW, how many is "many"? During my career I've never seen or
    spoken to anyone who'd "immediately dismiss Java". And, believe me,
    I've spoken to _many_.

    V
    Victor Bazarov, Jun 16, 2004
    #13
  14. Gaurav

    Allan Bruce Guest

    "Gaurav" <> wrote in message
    news:...
    > http://www.sys-con.com/story/print.cfm?storyid=45250
    >
    > Any comments?
    >
    > Thanks
    > Gaurav


    Have you seen the size of the programs he is running? This is no
    comparison, as the JVM may be much faster since the environment is already
    loaded into memory. If he was medium to large scale projects, I would be
    more keen to read the results.
    Allan
    Allan Bruce, Jun 16, 2004
    #14
  15. > >> So there are something that may be do in C++ and not in Java?
    > >
    > > writing an OS ( Kernel ) ?

    >
    > The "Church Thesis"


    nope.

    > or "Turing-machine-computable" or ...
    > ... means anything to you?


    partially (that's the way lots of cpu's work)

    >


    so please:
    -verbose

    TIA
    Rainer
    Rainer Hausbach, Jun 16, 2004
    #15
  16. > So there are something that may be do in C++ and not in Java?
    > Interesting...
    >
    > Please give me your curriculum, so I can hire you in my company!


    Well, how about:

    long a, b, double c;
    memcpy(&c, a, 4); memcpy(&c+4, b, 4);

    or:

    template <class T> T& min(T &tParam1, T &tParam2) ...

    or:
    #ifndef DONT_WANT_THIS
    gagagugu
    #endif
    Gernot Frisch, Jun 16, 2004
    #16
  17. Gaurav

    Mats Weber Guest

    C++ Intel vs GCC

    In article <>,
    "Gernot Frisch" <> wrote:

    >Next, gcc 3.3 is not really a good optimizing compiler. Better than
    >2.95, but not as good as say the intel or the codewarrior compilers.


    Interesting. I heard good things about the Intel compiler, so I
    downloaded a demo and compiled my code with it (simulation, physics,
    lots of object creation/destruction). And I found the code generated by
    Intel to be 10% slower than that from GCC 2.95. That was one year ago.
    Of course, I used the maximum machine specific optimization flags on
    both compilers.
    Mats Weber, Jun 16, 2004
    #17
  18. Re: C++ Intel vs GCC

    > Interesting. I heard good things about the Intel compiler, so I
    > downloaded a demo and compiled my code with it (simulation, physics,
    > lots of object creation/destruction). And I found the code generated

    by
    > Intel to be 10% slower than that from GCC 2.95. That was one year

    ago.
    > Of course, I used the maximum machine specific optimization flags on
    > both compilers.


    I use the GCC 3.4 vs the VS.net 7.1 compiler (which is from intel I
    think) and it gives me you experience in reverse...
    Maybe this is an ethic question? :)

    -Gernot
    Gernot Frisch, Jun 16, 2004
    #18
  19. Re: C++ Intel vs GCC


    > I use the GCC 3.4 vs the VS.net 7.1 compiler (which is from intel I
    > think) and it gives me you experience in reverse...
    > Maybe this is an ethic question? :)


    VC++ compiler is from Microsoft and Intel C++ compiler is from.. well,
    obviously Intel.
    =?ISO-8859-1?Q?Gon=E7alo_Ferreira?=, Jun 16, 2004
    #19

  20. > In every application (unless it's a really simple one) there are critical
    > parts where performance is paramount.


    An here is the contradction:
    > "All generalisations are wrong" -- unknown author. You would have to
    > put some numbers showing what you mean by "many". Is 10 out of 100000
    > -- many? IOW, how many is "many"?



    > During my career I've never seen or
    > spoken to anyone who'd "immediately dismiss Java". And, believe me,
    > I've spoken to _many_.


    I did. All of them are VC++ programmers.
    valentin tihomirov, Jun 16, 2004
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gaurav
    Replies:
    10
    Views:
    580
    Anon Amous
    Jun 18, 2004
  2. Andy Dingley
    Replies:
    45
    Views:
    1,640
    Andy Mabbett
    Jun 11, 2006
  3. llothar
    Replies:
    3
    Views:
    270
    Eric Sosman
    Mar 15, 2007
  4. RC
    Replies:
    2
    Views:
    435
    Chase Preuninger
    Jan 8, 2008
  5. Replies:
    3
    Views:
    467
    James Kanze
    Jul 10, 2008
Loading...

Share This Page