Java's performance far better that optimized C++

G

Gernot Frisch

Gaurav said:

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
 
M

Marcin Kalicinski

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
 
T

tom_usenet


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
 
J

Janusz Szpilewski

Gaurav said:

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
 
J

Jorge Rivera

Gaurav said:

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
 
V

valentin tihomirov

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

Guest

Gernot said:
✄
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
 
V

Victor Bazarov

Jorge said:
[...]
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
 
R

Rainer Hausbach

So there are something that may be do in C++ and not in Java?
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
 
G

Gernot Frisch

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
 
M

Mats Weber

Gernot Frisch said:
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.
 
G

Gernot Frisch

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
 
?

=?ISO-8859-1?Q?Gon=E7alo_Ferreira?=

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

valentin tihomirov

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top