[Haskell-cafe] Can Haskell outperform C++?
wren ng thornton
wren at freegeek.org
Wed May 23 06:30:17 CEST 2012
On 5/22/12 12:54 PM, Isaac Gouy wrote:
> On 5/21/2012 6:54 PM, Richard O'Keefe wrote:
>> For 50,000 nodes and 8,385,254 edges,
>> Java (first version) ran out of memory after 89.54 seconds (default heap)
>> Java (2nd version) 13.31 seconds -- avoid Integer boxing!
>> Java (3rd version) 15.07 seconds
>> Smalltalk 14.52 seconds
>> C 2.36 seconds
> fwiw my expectation is that Java would not be that much slower than C, and would be considerably faster than Smalltalk.
FWIW, that matches my expectations pretty well. Naive/standard Java
performing slower than Smalltalk; highly tweaked Java using non-standard
data types performing on-par with or somewhat faster than Smalltalk.
That C is 7x faster is a bit on the high end, but for something like
tsort I could imagine it'd be possible.
Do bear in mind that Java doesn't optimize ---that's the JIT's job---
and that the standard datatypes for Java are only good enough to suffice
for casual use and to be better than *naively* implementing them
yourself. They are extremely mediocre if you have any sort of
"specialized" needs. If you know what you're doing in designing data
structures, you can get amazing mileage out of writing a hand-tuned
implementation that (1) avoids boxing native types, (2) uses a
non-generic structure which has good complexities for the kinds of
operations you'll actually be using, and (3) doesn't bother trying to
implement the ridiculous APIs of the standard data types.
But even still, in my experience of using Smalltalk, the standard data
structures are much better done and so they will be on-par with what
you'd get from hand-tuning for Java. I've spent a lot of time trying to
get decent performance out of Java, not so much with Smalltalk; but the
performance with Smalltalk was sufficient that it wasn't needed so badly.
More information about the Haskell-Cafe