[erlang-questions] Speeding up text file I/O

Florian Weimer <>
Mon Jan 7 14:30:10 CET 2008


Is there a way to read lines from a text files more quickly than the
excerpt below?  This runs over 100 times slower than a "wc -l":

$ erlc wc.erl
$ erl -noshell -s wc process data -s erlang halt

I'm using erlang 1:11.b.5dfsg-12 (Debian) in this experiment.

-module(wc).
-export([process/1]).

processLines(File, Count) ->
    case io:get_line(File, '') of
	eof ->
	    io:format("~w~n", [Count]);
	_ ->
	    processLines(File, Count + 1)
    end.

process(Name) ->
    {ok, S} = file:open(Name, [read]),
    % ok = io:setopts(S, [binary]),
    processLines(S, 0).



More information about the erlang-questions mailing list