From: Chad Perrin Date: 2006-07-27T04:19:38+09:00 Subject: Re: For performance, write it in C On Thu, Jul 27, 2006 at 03:55:10AM +0900, Martin Ellis wrote: > Chad Perrin wrote: > > Haskell is a better choice than Java for performance: > > I suspect it depends what you're doing... To clarify: I meant "on average" or "in general". Obviously, there will be instances where Java will outperform Haskell or, for that matter, even C -- just as there are times Perl can outperform C, for an equivalent amount of invested programmer time, et cetera. I suspect the same is true even of Ruby, despite its comparatively crappy execution speed. That doesn't change the fact that in the majority of cases, Haskell will outperform most other languages. It is, after all, the C of functional programming. > > > in fact, the only thing keeping > > Haskell from performing as well as C, from what I understand, is the > > current state of processor design. > > I'm interested to know more about that. > Could you elaborate? A reference would do. I'm having difficulty finding citations for this that actually explain anything, but the short and sloppy version is as follows: Because imperative style programming had "won" the programming paradigm battle back in the antediluvian days of programming, processors have over time been oriented more and more toward efficient execution of code written in that style. When a new processor design and a new instruction set for a processor is shown to be more efficient in code execution, it is more efficient because it has been better architected for the software that will run on it, to better handle the instructions that will be given to it with alacrity. Since almost all programs written today are written in imperative, rather than functional, style, this means that processors are optimized for execution of imperative code (or, more specifically, execution of binaries that are compiled from imperative code). As a result, functional programming languages operate at a slight compilation efficiency disadvantage -- a disadvantage that has been growing for decades. There are off-hand remarks all over the web about how functional programming languages supposedly do not compile as efficiently as imperative programming languages, but these statements only tell part of the story: the full tale is that functional programming languages do not compile as efficiently on processors optimized for imperative-style programming. We are likely heading into an era where that will be less strictly the case, however, and functional languages will be able to start catching up, performance-wise. Newer programming languages are beginning to get further from their imperative roots, incorporating more characteristics of functional-style languages (think of Ruby's convergence on Lisp, for instance). For now, however, O'Caml and, even moreso, Haskell suffer at a disadvantage because their most efficient execution environment isn't available on our computers. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] "Real ugliness is not harsh-looking syntax, but having to build programs out of the wrong concepts." - Paul Graham