Arranging arguments for speed

Thomas Lindgren <>
Mon Mar 24 11:21:57 CET 2003


--- Roger Price <> wrote:
> Given a function such as
> 
>   f(X,alpha) -> ...;
>   f(X,bravo) -> ...;
>       .....
>   f(X,zebra) -> ... .,
> 
> would it run faster if re-written as
> 
>   g(alpha,X) -> ...;
>   g(bravo,X) -> ...;
>       .....
>   g(zebra,X) -> ... . ?
> 
> It was certainly the case for a Prolog system I once
> used, and I wondered
> if Erlang also used a hash of the function name and
> the first argument to
> find the clause.

There is luckily no need for that. The BEAM compiler
uses a more flexible algorithm than most Prologs. (The
reason is roughly that unification is hairier than
pattern matching, so one normally has to be more
conservative in a Prolog compiler.)

Try 'erl -S foo.erl' to get the BEAM code for foo and
see if it looks right. 

Best,
Thomas


__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com



More information about the erlang-questions mailing list