Coolest D features

Benji Smith dlanguage at benjismith.net
Wed Dec 27 13:22:56 PST 2006


Waldemar wrote:
> Actually, the reality is Java is plenty slow in many applications. There is JNI
> for a reason.  Never mind cases where Java is not even considered (fast servers,
> OS internals, communication, graphics, driveres, embedded, etc, etc.)  As soon as
> Java reaches C/C++ speed, C++ will disappear.  Not too worry, won't happen any
> time soon.
> 
> Having said that, there is always a danger that Sun develops "low level Java" with
> performance truly matching C++.   If that happens D might as well close the shop.
>  Same thing with C#.  MS can definitely do it.  At the moment they go with this
> "safer" C/C++ with many custom libs and features.  But you can feel it's just one
> more step, so watch out.

Last year, I developed a pretty sophisticated machine learning algorithm 
for my company. The training phase of the algorithm needs to read 5 or 6 
gigabytes of data, create incremental indices of commonly occurring 
features in many different categories, conduct a statistical analysis of 
all categorical feature histograms, and then plot each of the indices in 
n-dimensional vector space to create agglomerative category clusters.

There's lots of I/O, and plenty of math involved.

I wrote the code in Java. Thanks to the language's consistent, 
orthogonal semantics, the code is very easy to read and understand. With 
only a little profiling and a few tiny optimization tweaks, I was very 
satisfied with performance.

Then, because this algorithm needed to be deployed to heterogeneous 
environments, a colleague of mine ported my code to C++. He did a 
straight transliteration of the code, preserving the same semantics from 
the Java to C++.

When we timed both implementations, we discovered that mine was 40 
percent faster. Several of the C++ developers on my team were completely 
  incredulous, and they made it their personal quest to optimize the C++ 
version so that it was the performance winner.

They eventually caught up to, and surpassed, the performance of the Java 
code. But only after introducing a bunch of ugly optimizations, making 
the code much more difficult to follow. Of course, the types of 
optimizations that they performed are unavailable in Java.

The moral of the story is that the JVM is fast. Very fast. And 
straightforward implementations of algorithms are often faster in Java 
than in C++. But C++ provides a broader suite of possible 
micro-optimizations, so it's possible to bend over backwards in order to 
write *really* fast code. But, when writing equivalent code in C++ and 
Java, it's tough to say which will have better performance characteristics.

To echo what others have said before me, you will *never* win over any 
Java programmers to D by emphasizing performance.

The lack of a VM requirement, on the other hand, is very compelling.

--benji



More information about the Digitalmars-d mailing list