[erlang-questions] Erlang vs IO
Imre Palik
imre@REDACTED
Wed Sep 3 16:27:23 CEST 2008
Hi,
It is me messing up something, or the IO in erlang is quite slow? I run the following program on a largish file:
-module(intest).
-export([run/0]).
problem_loop(0, _, Acc) ->
io:fwrite("~w~n", [Acc]),
void;
problem_loop(I, D, A) ->
{ok, [V]} = io:fread([], "~d"),
if
0 == V rem D ->
problem_loop(I - 1, D, A + 1);
true ->
problem_loop(I - 1, D, A)
end.
run() ->
{ok, [Iter, Div]} = io:fread([], "~d ~d"),
problem_loop(Iter, Div, 0).
Then both of my cores started to run at 100%, which I find weird in itself with an IO bound problem. Also, I compared the runtime with the following program written in scheme
#!/usr/bin/guile -s
!#
(define (intest iter div acc)
(if (= iter 0)
(display acc)
(if (= 0 (remainder (read) div))
(intest (- iter 1) div (+ acc 1))
(intest (- iter 1) div acc))))
(intest (read) (read) 0)
The scheme implementation was 10 times as fast as the erlang, and it only used one of the cores.
How can I get a decent IO performance out of erlang? Am I making some mistakes in my erlang code? Should I upgrade my erlang system? (I am running R12B on windows)
Thx.
ImRe
More information about the erlang-questions
mailing list