Java's performance far better that optimized C++

V

valentin tihomirov

Rainer Hausbach said:
writing an OS ( Kernel ) ?

You, C programmers cannot imagine that C is just one of general purpose
programming languages. It is far from the perfect, dealing with "include"s
we get huge problems with scopes and compilation time takes 1000 times
longer than say Pascal. You console oneself that bad structure of C lang and
slow compiler lead to more optimal code. In fact, kernel can be written in
any general purpose language. The is nothing against laws of the Nature.

In fact, I yould agree with origianl poster, there is one thing. OOP
programming (dynamic memory allocation) enforced by garbage collection makes
it hard to build real-time systems due to non-deterministic responce times.
 
G

Guest

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

C sintactic sugar!

Every program you can write in C or C++ may be written
in any other-language that can emulate a Turing-machine
(Cobol, Fortran, APL, PL/!, Algol, Ada, Pascal, Java, C#, etc...).

- Dario
 
G

Guest

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

so please:
-verbose

Every program you can write in C or C++ may be written
in any other-language that can emulate a Turing-machine
(Cobol, Fortran, APL, PL/!, Algol, Ada, Pascal, Java, C#, etc...).

- Dario
 
V

valentin tihomirov

So there are something that may be do in C++ and not in Java?
long a, b, double c;
memcpy(&c, a, 4); memcpy(&c+4, b, 4);

byte[] a = new byte[100];
byte[] b = new byte[100];
System.arraycopy(a, 0, b, 0, 100);

or:

template <class T> T& min(T &tParam1, T &tParam2) ...
You may wonder but since java 1.5 there is support for generics.



or:
#ifndef DONT_WANT_THIS
gagagugu
#endif

Remember that java is a multiplatform enviroment thus constructs like these
never bloat your code:
#ifndef cpp_precompiler_sucks_on_Win
aaa
#endif

Use natural constructions like.
If (false) { }
Any good compiler will optimize unused code out. (I know that C
compiler+precompiler) have many things to do besides compilation.



What about such inveronments like Intellij? I don't like idea writing
programs in Visual notepad in 21st century. C++ will never have such one.
C++ will always get problems with includes, slow compilers and unresolved
references. I hate the idea when compiler cannot show me errorous line of
code. IntelliJ checks synthax yet while you're typing, completes reference
to not imported elements.


Remember, a good programmer writes a good program in C++ and Java. Bad
programmer writes bad programs on C+ and Java. Both make faster on
developer-friendly in Java. C++ will never evelove into something friendly
like Delphi/Java langs/environments.


The most important point, JAVA DOES NOT HAVE INCLUDES!!
 
T

tom_usenet

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

byte[] a = new byte[100];
byte[] b = new byte[100];
System.arraycopy(a, 0, b, 0, 100);

or:

template <class T> T& min(T &tParam1, T &tParam2) ...
You may wonder but since java 1.5 there is support for generics.

It's very basic compared to C++ templates.
What about such inveronments like Intellij? I don't like idea writing
programs in Visual notepad in 21st century. C++ will never have such one.
C++ will always get problems with includes, slow compilers and unresolved
references. I hate the idea when compiler cannot show me errorous line of
code. IntelliJ checks synthax yet while you're typing, completes reference
to not imported elements.

I use IntelliJ, and I agree that it would be very hard to produce a
similar IDE for C++. The CDT project in Eclipse is proving this I
think...
The most important point, JAVA DOES NOT HAVE INCLUDES!!

Modular languages do make writing good IDEs for them much easier. Java
has other problems though, of course, mostly memory usage, start-up
time and performance related.

Tom
 
M

Marcin Kalicinski

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? :)

Some time aho I was inspecting machine code generated by Intel compiler.
Although the compiler did so called "profile based optimizations", it
sometimes failed to apply some some simpler optimizations, like loop
unrolling or use of CPU string instructions. Visual C++ .NET code was
performing significantly faster, although without profile based
optimizations.

Best regards,
Marcin
 
V

Victor Bazarov

valentin said:
[...]
Remember that java is a multiplatform enviroment [...]

That's a very common newbie misconception. Java _is_ a platform.
And constructs like
#ifdef some_platform_or_other
...
don't bloat _my_ code. They bloat the code of the JVM, and the
necessity to run a JVM _always_ bloats the resulting program.
[...]
The most important point, JAVA DOES NOT HAVE INCLUDES!!

Another common misconception. What's Java's "import" if not
an include? Oh, wait, if it's not spelled "include", but is
spelled "import", it must be something entirely different... NOT!
 
D

Default User

Gaurav wrote:


Comparisons with other languages are not topical in comp.lang.c++.




Brian Rodenborn
 
V

valentin tihomirov

We're C++ programmers, please do not confuse the two.

C++ is a superset of C. Therefore, to be a valid C++ programmer you need to
be C programmer(neobhodimoe uslovie), OK? The most features of C++ I hate
are derived from C.
 
V

valentin tihomirov

Victor Bazarov said:
valentin said:
[...]
Remember that java is a multiplatform enviroment [...]

That's a very common newbie misconception. Java _is_ a platform.

- my computer is fast
- no, it is black.
True and false simultaneously. Java is a platform. It runs on multiple
platforms underlying.

And constructs like
#ifdef some_platform_or_other
...
don't bloat _my_ code. They bloat the code of the JVM, and the
necessity to run a JVM _always_ bloats the resulting program.
The fact that java is a multiplatfom means it is a sigle platform and such
constructs are not useless in java. I'm not familiar with is the definition
of resulting program. Running is not any way more hard that just to extecute
another program.



[...]
The most important point, JAVA DOES NOT HAVE INCLUDES!!


Another common misconception. What's Java's "import" if not
an include? Oh, wait, if it's not spelled "include", but is
spelled "import", it must be something entirely different... NOT!

The problem is not in spelling, it is in the sence. At first, includes break
your code. Using C++ I've written a class that compiles without any errors.
Once imported, Im' getting compilation errors on the calss. With a STUPID
C++ compiler (after sloooowly analizing my source codes) it is extremely
hard to find source of error. The compiler whether does not jump to a line
produced the error or jumps to a syntactically correct piece of code.
The second problem is compilation time and worknig directory sizes which are
orders of magnitude slower/bigger . May be I'm mistaken associating these
fundamental problems of C to "include" but these problems merely do not
exist on compiles of langs not aware of "include".

BTW, Java's imports are similar to Delphi's units.
 
V

Victor Bazarov

valentin said:
C++ is a superset of C. Therefore, to be a valid C++ programmer you need to
be C programmer(neobhodimoe uslovie), OK?

Not OK. And do not use the language others won't understand, OK?
The most features of C++ I hate
are derived from C.

It seems that the hate is muddying the waters for you. C++ is NOT
a superset of C.
 
V

valentin tihomirov

C++ is a superset of C. Therefore, to be a valid C++ programmer you need
to
Not OK. And do not use the language others won't understand, OK?


It seems that the hate is muddying the waters for you. C++ is NOT
a superset of C.

Seems you're right, C isn't a subset of C++ in the strict mathematical
sense. But according to Bjarne Stroustrup:
http://www.research.att.com/~bs/bs_faq.html#C-is-subset :
C++ is as much a superset of ANSI C. The nagative attitude, opposition is
coming from irrationality of the languages and the fact that these ugly
langugages are dictated to the world (english belongs to this group).
 
T

Thore Karlsen

C sintactic sugar!

Every program you can write in C or C++ may be written
in any other-language that can emulate a Turing-machine
(Cobol, Fortran, APL, PL/!, Algol, Ada, Pascal, Java, C#, etc...).

Great, then we don't need any of those languages. To hell with
practicality, all we need is machine code.
 
R

Rajeev Ayyagari

tom_usenet said:
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).

What is the flaw in this benchmark, other than not unrolling loops
(which is probably a big flaw)?
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.

Yes, -O2 doesn't unroll loops (-O3 doesn't either). The benchmarks
would have been more interesting if the -funroll-loops option was
used. But I think the results are still startling, considering that
Java is interpreted. Maybe the fault is with g++'s optimization.
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.

This is not a valid way of benchmarking. To compare the performance,
you need to test the same algorithm coded in both languages. You
can't code a logarithmic time algorithm in C++ and an exponential-time
one in Java for the same problem and use the results to claim that C++
is faster.
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;
}

But this is changing the algorithm. The benchmark algorithm was an
exponential-time algorithm; the one you've written is linear time.
There is a logarithmic-time algorithm as well, but you can't compare
that with the algorithm used in the benchmark. You would have to
compare the above code with the *same* algorithm, coded in Java. The
algorithm used in the benchmarks is well-known to be a particularly
bad one for generating Fibonacci numbers, but the point is moot. In
the benchmark, you have to test the same algorithm in both languages,
not a fast algorithm coded in C++ against a slow one coded in Java.

Regards,
Rajeev.
 
J

Jerry Coffin

[ ... ]
Every program you can write in C or C++ may be written
in any other-language that can emulate a Turing-machine
(Cobol, Fortran, APL, PL/!, Algol, Ada, Pascal, Java, C#, etc...).

That's not really true. It's true that an algorithm that can be
implemented in one Turing complete language can also be implemented in
any other Turing complete language. Implementing an algorithm,
however, is somewhat different from implementing a complete program or
(as was mentioned earlier) something like an OS.

Just for example, somewhere in the OS (hopefully in a device driver)
you need some code that simply displays things on the screen. In C or
C++ that's often quite trivial -- for example, on one popular
platform, some (non-portable) code like this:

int *screen = (int *)0xb80000;

will give you direct access to the machine's text-mode screen buffer.
It's not portable, but for the target hardware it works perfectly
well.

Java doesn't allow things like that. Direct access to the hardware
isn't portable in C or C++, but Java simply doesn't allow it at all.

In the end, there's another major problem: Java is defined as more
than a language. Even if you accept source code that's syntactically
identical to Java's, if you compile it directly to native machine code
(other than for a Java machine) what you have isn't Java anymore.

This means that attempting to implement a Java Virtual Machine in Java
leads directly to infinite recursion -- to work, it HAS to be written
in something else.

Turing was right, but his result means less than you seem to think it
does.
 
V

Victor Bazarov

X-No-archive: yes
valentin tihomirov said:
Seems you're right, C isn't a subset of C++ in the strict mathematical
sense. But according to Bjarne Stroustrup:
http://www.research.att.com/~bs/bs_faq.html#C-is-subset :
C++ is as much a superset of ANSI C.

Applying well known tactics of incomplete quotes, eh?
The nagative attitude, opposition is
coming from irrationality of the languages and the fact that these ugly
langugages are dictated to the world (english belongs to this group).

Aw, you poor sod, feeling oppressed and forced into using such ugly
languages like English and C++... I am so sorry for you... Get
a grip! If you don't like it, don't use it. Go flip a burger or
something.
 
M

Mark A. Gibbs

Dario said:
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!

///////////////////////////////////////////////////////////////////////////
[answer 1 - fun stuff ^_^]

#include <iostream>

int main()
{
using namespace std;

goto start;

done:
return 0;

last:
cout << "completely backwards! ^_^" << endl;
goto done;

next:
cout << "run a program ";
goto last;

start:
cout << "let's see java ";
goto next;
}

///////////////////////////////////////////////////////////////////////////
[answer 2 - template metaprogramming]

#include <iostream>

template <int N>
class compile_time_factorial
{
public:
static const int return_value =
compile_time_factorial<N - 1>::return_value * N;
};

template<>
class compile_time_factorial<0>
{
public:
static const int return_value = 1;
};

#define factorial(n) compile_time_factorial<n>::return_value;

int main()
{
using namespace std;

cout << "\n!3 = " << factorial(3);
cout << "\n!4 = " << factorial(4);
cout << "\n!5 = " << factorial(5);

return 0;
}

///////////////////////////////////////////////////////////////////////////
[answer 3 - templates period, java generics suck]

#include <iostream>
#include <string>
#include <sstream>

template <typename T>
class numbers_only_writer
{
// Leave blank for build time error
// or implement string write(T const&); that throws an
// exception for a compiler time error
};

#define NUMBER_WRITER_CLASS(T) template <> \
class numbers_only_writer<T> \
{ \
public: \
static std::string write(T const& t) \
{ \
std::eek:stringstream str; \
str << t; \
return str.str(); \
} \
}

NUMBER_WRITER_CLASS(int);
NUMBER_WRITER_CLASS(float);
NUMBER_WRITER_CLASS(unsigned short);
// etc.

#undef NUMBER_WRITER_CLASS

template <typename T>
inline std::string number_only_write(const T& t)
{
return numbers_only_writer<T>::write(t);
}

int main()
{
using namespace std;

cout << "int write: " << number_only_write(2) << endl;
cout << "float write: " << number_only_write(3.14f) << endl;
cout << "unsigned short write: " <<
number_only_write(static_cast<unsigned short>(2)) << endl;
//cout << "char write (uh oh!): " << number_only_write('c') << endl;

return 0;
}

///////////////////////////////////////////////////////////////////////////
[answer 4 - create executables that cannot be trivially decompiled]

///////////////////////////////////////////////////////////////////////////
[answer 5 - tell me what's in my cpu's edx register]

///////////////////////////////////////////////////////////////////////////
[answer 6 - write device drivers]

///////////////////////////////////////////////////////////////////////////
[answer 7 - run a reasonably interesting game on my gba]



i'll pass on that job offer, though. from what you've demonstrated of
the level of technical expertise there, i'm afraid it won't be around
long enough for me to make the walk over.

indi
 

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