View Single Post
Posts: 376 | Thanked: 511 times | Joined on Aug 2009 @ Greece
#54
Originally Posted by 406NotAcceptable View Post
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.
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):
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);
}
Not only he could just have done:
Code:
return malloc(rows*cols*sizeof(int))
and accomplish a N-times faster program, he uses malloc instead of new in a C++ program.

As for the second site, writing something like this:
Pointers make optimization hard
makes me stop reading (why mention pointers when talking about C++? where are your references?). But I continued:

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

Last edited by v13; 2009-11-21 at 23:08.