The Great Computer Language Shootout is back

Mark Scandariato mscandar@REDACTED
Tue Jul 27 22:55:04 CEST 2004


How about:

-module(wc).
-compile(export_all).

start(File) ->
     {ok, F} = file:open(File, [raw, read, binary]),
     s(next({F, 0, <<>>}), 0, 0).

next({F, C, <<Char:8, Rest/binary>>}) ->
     {Char, {F, C+1, Rest}};

next({F, C, <<>>}) ->
     case file:read(F, 4096) of
         {ok, Bin} -> next({F, C, Bin});
         eof -> {eof, C}
     end.

s({eof, C}, L, W) -> {L, W, C};
s({$\s, S}, L, W) -> s(next(S), L, W);
s({$\t, S}, L, W) -> s(next(S), L, W);
s({$\n, S}, L, W) -> s(next(S), L+1, W);
s({_, S}, L, W)   -> w(next(S), L, W+1).

w({eof, C}, L, W) -> {L, W, C};
w({$\s, S}, L, W) -> s(next(S), L, W);
w({$\t, S}, L, W) -> s(next(S), L, W);
w({$\n, S}, L, W) -> s(next(S), L+1, W);
w({_, S}, L, W)   -> w(next(S), L, W).


Not too pretty (but not too ugly either :-) and fairly fast.

Mark.

Brent Fulgham wrote:

> --- Isaac Gouy <igouy2@REDACTED> wrote:
> 
>>Last month there were a few postings about the
>>Erlang code in "The
>>Great Computer Language Shootout"
>>http://shootout.alioth.debian.org/lang/erlang/
>>
>>
>>>Bengt Kleberg wrote:
>>>i have sent a wc.erl (see below)
>>
>>My guess is that this solution exceeds the max time
>>allowed by the
>>Shootout test program. 
>>
>>Using the same approach for sumcol takes ~51s on my
>>machine with
>>Standalone Erlang (probably over the max time on the
>>Shootout test
>>machine). How do we do this faster?
> 
> 
> Yes -- the tests are failing due to timeouts.  I keep
> imagining that I will find the time to figure out the
> problem, but to date have not.
> 
> 
> 
>>>Marc van Woerkom wrote:
>>>Shoutout benchmark did not use native compilation
>>
>>So let us know how to use native compilation! 
>>Use the Shootout mailing list, or email Brent.
> 
> 
> True.  However, I created a "HIPE" entry for
> native-compiled Erlang.  Unfortunately, this does not
> seem to make a substantial difference in this case (or
> perhaps I am passing the wrong options to the
> compiler).
> 
> This has the feel of an alogrithm problem.  I know
> Erlang is quite bad at text munging (bad just meaning
> speed in this context), but this is a very poor
> result.  I'm sure there is a better solution to avoid
> the timeout.
> 
> Thanks,
> 
> -Brent



More information about the erlang-questions mailing list