Article View: comp.lang.functional
Article #1120Re: Why such poor recursive behaviour?
From: Jon Harrop
Date: Mon, 04 Aug 2008 14:33
Date: Mon, 04 Aug 2008 14:33
75 lines
4513 bytes
4513 bytes
namekuseijin wrote: > I wonder why most functional programming languages fail so badly at > what should be one of their primary main strengths: recursive > functions. > > In the well-known benchmarking game called "The computer game > shootout", most such languages fail miserably in the face of blazing > fast imperative code during the benchmarking of recursive functions > such as ackermann or fibonacci: > > http://shootout.alioth.debian.org/gp4/benchmark.php?test=recursive&lang=all > > The best is clean, only 1.6 slower than gcc C. Actually the best is F#, only 1.2x slower than Visual C++. > The chart: > 1.6 Clean > 3.2 OCaml (just behind Fortran and Java!) > 3.3 F# (running in mono) > 3.4 SML on MLton (just after FreeBasic!) > 3.4 Haskell GHC (just after Java on gcj! almost a tie-in) > 3.6 CL on SBCL (almost as good as compiled lazy static Haskell) > 3.7 Scheme on Chicken (just after sbcl) > 4.0 SML/NJ (just after C# on mono) > 4.6 Scheme on Ikarus (just after Java -client!) > 8.1 Scheme PLT (just after Fortran, again) > > Well, that's about it. > > I know in the grand scheme of things, such timings are not that bad, I think 3x slower is bad. These languages should be at most 2x slower. > not orders of magnitude slower like some of the dynamic scripting > stinkers in the bottom, specially in the face of such classy and easy > syntax and semantics adding to programmer productivity. Still, kind > of a let down, like buying a Playstation 3 and waiting for a killer > app that never comes... > > Any thoughts? OCaml is slow on the int versions because integer arithmetic is slow in OCaml because it uses tagged 31-bit integers for the GC that require extra shifts and tests, e.g. OCaml is 3x slower than F# on the int-based Monte Carlo part of the SciMark2 benchmark (see the OCaml Journal article for details). OCaml is slow on the float versions because it is unable to unbox floats passed by recursive function calls. The latter problem can be solved without leaving OCaml by rewriting in Fortran 77 style but it is ugly. .NET's JIT-time monomorphization solves these problems in F# and, consequently, F# on .NET is often much faster than any other FPL including OCaml. Moreover, the designs of all of those FPLs predate VMs like the JVM and .NET which is why none of them are capable of these kinds of optimization. This is not rocket science but, despite the availability of excellent solutions like LLVM, there are no longer any modern open source functional programming language implementations. This is a great shame because functional programming is really taking off right now and a lot of people would benefit from a decent foundation. The problem is that the programming language researchers are the only people who know what they are doing but they have no incentive to build decent foundations for the next generation of functional programming languages. So they are all building separately on sand, Greenspunning uninteroperable run-time environments and garbage collectors. Mono is the nearest thing to an alternative (the JVM lacks tail calls) but it is a joke compared to .NET, as you have shown. So Microsoft now have a monopoly over modern functional programming languages. -- Dr Jon D Harrop, Flying Frog Consultancy http://www.ffconsultancy.com/products/?u
Technical Details
Message-ID:
<g773us$b85$1@aioe.org>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder.news-service.com!newsfeed0.kamp.net!newsfeed.kamp.net!news.k-dsl.de!aioe.org!not-for-mailReferences:
<525fb940-a88e-4276-bd80-86b0b178a08a@m3g2000hsc.googlegroups.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 107f24,904ab2e1d637ae0f X-Google-Thread: ff861,904ab2e1d637ae0f X-Google-Thread: 10707f,904ab2e1d637ae0f X-Google-Thread: 103d24,904ab2e1d637ae0f X-Google-Thread: f4fd2,904ab2e1d637ae0f X-Google-Attributes: gid107f24,gidff861,gid10707f,gid103d24,gidf4fd2,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder.news-service.com!newsfeed0.kamp.net!newsfeed.kamp.net!news.k-dsl.de!aioe.org!not-for-mail From: Jon Harrop <jon@ffconsultancy.com> Newsgroups: comp.lang.functional,fa.caml,fa.haskell,comp.lang.scheme,comp.lang.lisp Subject: Re: Why such poor recursive behaviour? Followup-To: comp.lang.functional Date: Mon, 04 Aug 2008 15:33:50 +0100 Organization: Flying Frog Consultancy Ltd. Lines: 75 Message-ID: <g773us$b85$1@aioe.org> References: <525fb940-a88e-4276-bd80-86b0b178a08a@m3g2000hsc.googlegroups.com> NNTP-Posting-Host: MmEzDQ6zdXIvn2v5W1Df7w.user.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/0.10.9