Some lazy code to D

Marco Leise Marco.Leise at gmx.de
Wed Aug 29 14:06:39 PDT 2012


Am Wed, 29 Aug 2012 13:56:12 +0200
schrieb "bearophile" <bearophileHUGS at lycos.com>:

> It runs the (8, 13) case (40_489 solutions) in less than half 
> second, about eleven times faster than the Haskell version.
> 
> I think the Haskell run-time is re-using some thunks of precedent 
> lazy computations, so I think Haskell is doing a kind of 
> automatic partial memoization.
> 
> Bye,
> bearophile

I've made the experience with another (non-professional)
Haskell programmer, that my first attempts in D are sometimes
slower than the Haskell version. And also he could show me
that there are some low hanging fruits when it comes to
optimizations in Haskell that can literally double the speed.
I don't know what it was though - some sort storage class flag
in any case. In D the optimization possibilities are almost
endless, but also require deeper knowledge of the machine and
caches.
I guess the point I want to make is that Haskell isn't half
bad with the optimizing compiler. The native efficiency is
comparable to D until you really start to optimize. And this
thread shows, that idiomatic D code can even fall behind when
you don't pay attention.
Maybe if I wasn't such a control junkie I would use it, too. :D

-- 
Marco



More information about the Digitalmars-d mailing list