[erlang-questions] Erlang vs IO

Alpár Jüttner <>
Thu Sep 4 14:14:57 CEST 2008


> Greetings,
> 
> If you are reading a file (as opposed to stdin) you can use
> file:read_file/2 (if you have enough RAM) or file:read/2 (after using
> the flag 'raw' when doing file:open/2).
> 

Could you explain it a little bit more?
I'm very interested to see how to transform the code example of the
original question to use file:read_file/2 or file:read/2.

Best regards,
Alpar

> 
> bengt
> 
> On Wed, 2008-09-03 at 17:27 +0300, Imre Palik wrote:
> > 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
> > _______________________________________________
> > erlang-questions mailing list
> > 
> > http://www.erlang.org/mailman/listinfo/erlang-questions
> 
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list