![]() |
2009-11-21
, 22:32
|
Posts: 2,014 |
Thanked: 1,581 times |
Joined on Sep 2009
|
#52
|
C++ (and C) (in contrast with Java) are very well defined. C++ is exactly the ISO/IEC 14882:2003 and that includes the string library (section 21 of the standard).
Java on the the other hand... well...
So please, don't compare those two (three) languages. Java is just a product that a company defines while C++ is a standard. There is no limitation on what you can do with C++ and even the oldest C++ programs still compile and run. Java OTOH has a great number of limitations and questioned backward compatibility.
Of course C beats' em all on those aspects
![]() |
2009-11-21
, 22:55
|
Posts: 1,255 |
Thanked: 393 times |
Joined on Oct 2009
@ US
|
#53
|
![]() |
2009-11-21
, 22:57
|
Posts: 376 |
Thanked: 511 times |
Joined on Aug 2009
@ Greece
|
#54
|
Java really isn't as slow as many would make you believe.
http://kano.net/javabench/
http://www.idiom.com/~zilla/Computer...benchmark.html
Certain operations can be slightly faster, whilst others are upto 10% slower.
int **mkmatrix(int rows, int cols) { int i, j, count = 1; int **m = (int **) malloc(rows * sizeof(int *)); for (i=0; i<rows; i++) { m[i] = (int *) malloc(cols * sizeof(int)); for (j=0; j<cols; j++) { m[i][j] = count++; } } return(m); }
return malloc(rows*cols*sizeof(int))
Pointers make optimization hard
Garbage collection- is it worse...or better?
....
Consider what happens when you do a new/malloc: a) the allocator looks for an empty slot of the right size, then returns you a pointer. b) This pointer is pointing to some fairly random place.
With GC, a) the allocator doesn't need to look for memory, it knows where it is,
....
The big benefit of GC is memory locality. Because newly allocated memory is adjacent to the memory recently used, it is more likely to already be in the cache.
![]() |
2009-11-21
, 22:58
|
Posts: 189 |
Thanked: 121 times |
Joined on Oct 2009
|
#55
|
Since Droid does a great job with emulators but can't play Quake 1 very well due to the overhead, my guess is the N900 will kick Droid's a55 for emulators.
![]() |
2009-11-21
, 23:00
|
Posts: 1,255 |
Thanked: 393 times |
Joined on Oct 2009
@ US
|
#56
|
Both sites seem like FUD to me.
The first site doesn't compare the languages at all. It just compares different algorithms: The java's algorithm and the author's algorithm for each example.
For god's sake, who allocates a matrix that will hold integers in C++ like this (matrix.cpp):
Not only he could just have done:Code:int **mkmatrix(int rows, int cols) { int i, j, count = 1; int **m = (int **) malloc(rows * sizeof(int *)); for (i=0; i<rows; i++) { m[i] = (int *) malloc(cols * sizeof(int)); for (j=0; j<cols; j++) { m[i][j] = count++; } } return(m); }
and accomplish a 1000-times faster program, he uses malloc instead of new in a C++ program.Code:return malloc(rows*cols*sizeof(int))
As for the second site, writing something like this:
makes me stop reading (why mention pointers when talking about C++? where are your references?). But I continued:
at this point the author compares the internal memory allocating method of the c library with the C (and C++) language. That's totally wrong and can be proved by looking at glibc and montern operating systems: glibc used not to free memory at all but instead re-use it (what the author wants) but that was changed and now it lets the kernel manage the memory more efficient. In fact, since all memory is virtual (and most of the time it is split in 4KB pages), there is no guarantee that two consecutive memory addresses will in fact be consecutive (or in cache). Of course, all these are operating system dependent and the OS tries to do its best. Java just builds a layer on top of this.
OK, Java's speed is acceptable, but the sites should have more serious claims...
p.s. I could keep commenting on almost all lines of those sites for hours, but you get the point
![]() |
2009-11-22
, 01:52
|
Posts: 1 |
Thanked: 1 time |
Joined on Nov 2009
@ Rio de Janeiro, RJ - Brazil
|
#57
|
![]() |
2009-11-22
, 07:37
|
Posts: 1,418 |
Thanked: 1,541 times |
Joined on Feb 2008
|
#58
|
The syntax and semantics of a language do not denote it "being" that language - the interpreter of that syntax and semantics are what define that.
It is entirely possible you could write an interpreter for the Java syntax etc that in no way produced the same output as the Java interpreter.
Finally - To legally call something Java compliant you do have to get sign off from Sun. Anything else is technically not Java compliant and thus not "really" Java.
Java on the the other hand... well...
So please, don't compare those two (three) languages. Java is just a product that a company defines while C++ is a standard. There is no limitation on what you can do with C++ and even the oldest C++ programs still compile and run. Java OTOH has a great number of limitations and questioned backward compatibility.
Of course C beats' em all on those aspects