[Haskell-beginners] Performance of Idiomatic lazy Haskell

Markus Böhm markus.boehm at googlemail.com
Mon Feb 1 08:31:40 EST 2010


Daniel, with LuaJIT it needs 1.45 sec cpu-time on my machine with
attached variant. I compiled all our Haskell variants with ghc --make
-O2. I don't know about -fvia-C, have to find out. I hope I didn't
distract You with my Lua variant. In any case thank You very much for
your advice. Markus.


print("EPS: ")
EPS = io.read("*number")
local x = os.clock()
pi2 = 1
i = 3
s = false
repeat
    pi1 = pi2
    if s then
        pi2 = pi1 + 1.0/i
        s = false
    else
        pi2 = pi1 - 1.0/i
        s = true
    end
    i = i+2

until EPS > 4.0 * math.abs(pi2-pi1)

print("PI mit EPS", EPS," = ",4*pi1," n= ",(i-3)/2)
print(string.format("elapsed time: %.2f\n", os.clock() -x))

-- Markus




On Mon, Feb 1, 2010 at 2:16 PM, Daniel Fischer <daniel.is.fischer at web.de> wrote:
> Am Montag 01 Februar 2010 10:37:41 schrieb Markus Böhm:
>> Daniel, Stephen, Felipe thanks for Your answers/advice, which I
>> studied this morning. Helps me a lot on my learning curve. I guess it
>> takes some time to get a feeling for the performance/runtime behaviour
>> of abstractions in Haskell.
>>
>> Just for fun and w/o knowing Lua: I translated my Haskell
>> "loops-while"-version into Lua
>
> That's not quite a translation of the loop you posted. Not really
> important, though, small difference.
>
>> and ran on LuaJit Beta 2.0.0. Seems to
>> beat our best Haskell version.
>
> So LuaJit Beta 2.0.0 beats gcc -O3 on such a simple loop?
> I'm not going to install Lua to test, but if that's really the case, I'm
> sure the folks at gnu.org would like to hear about it.
> Or don't you consider -fvia-C compiled loops to be true Haskell versions?
>
>>
>> print("EPS: ")
>> EPS = io.read("*number")
>> pi2 = 1
>> i = 3
>> s = false
>> repeat
>>     pi1 = pi2
>>     if s then
>>         pi2 = pi1 + 1.0/i
>>         s = false
>>     else
>>         pi2 = pi1 - 1.0/i
>>         s = true
>>     end
>>     i = i+2
>>
>> until EPS > 4.0 * math.abs(pi2-pi1)
>>
>> print("PI mit EPS", EPS," = ",4*pi1," n= ",(i-3)/2)
>>
>>
>> -- Markus
>


More information about the Beginners mailing list