Erlang Efficiency quesitons

Robert Virding rv@REDACTED
Wed Mar 14 23:17:27 CET 2001


Francesco Cesarini <cesarini@REDACTED> writes:
>At the time it was better to group clauses according to the matching
>which had to be done. For example
>
>case X of
>  {a,b,c} -> ..
>  {b,c,A} -> ..
>  {A,B,C} -> ...
>  {a,b}   -> ...
>  {A,b}   -> ..
>  true    -> ..
>end
>
>was more efficient than :
>
>case X of
>  {a,b,c} -> ..
>  true    ->  
>  {a,b}   -> ...
>  {A,b}   -> ..
>  {b,c,A} -> ..
>  true    -> ..
>  {A,B,C} -> ...
>end

Today there is no difference with type of grouping.  The compiler rearranges 
clauses after type of match argument anyway.  The only rule that would aid 
speed is to group clauses where there is a variable to match on instead of 
interspersing them among other clauses.  Avoid if possible:

case X of
  {a,b,c} -> ..
  Sune when ...   ->  
  {a,b}   -> ...
  Curt when ...   -> ..
  {b,c,A} -> ..
  Other when ..   -> ..
  {A,B,C} -> ...
end

Of course this is often not possible to do but is worth remembering.

	Robert





More information about the erlang-questions mailing list