Slow Erlang code to find Pythagorean triplets Why does this Erlang code take about one minute on my machine?

On Pascal something like this took less then second on my machine.

What I can do to speed it up?

-module(slow).
-export([slow/0]).

pyth(N) -&gt;
    [{A, B, C} ||
        A &lt;- lists:seq(1, N - 2),
        B &lt;- lists:seq(A + 1, N - 1),
        C &lt;- lists:seq(B + 1, N),
        A + B + C =&lt; N,
        A * A + B * B == C * C].

slow() -&gt; io:format("~p\n", [pyth(1000)]).
Erlang runs on a VM, so you will get better performance on such a pure arithmetic computation by compiling it into native code using HIPE.

From the command line:

erlc +native slow.erl


Or from the Erlang shell:

1&gt; hipe:c(slow).


Or:

1&gt; c(slow, [native]).