[erlang-questions] The is_record() guard

Steve Davis steven.charles.davis@REDACTED
Sat Jul 25 22:39:24 CEST 2009


Hi Bjorn,

Definitely the approach suggested by Oscar shows much better numbers in 
fprof...

I also see other cases where functions that filter arguments using 
guards appear to be (quite a bit) less efficient than direct matches on 
the arguments.

Would it be fair to say that, where possible. pattern matching function 
arguments is in general more efficient than using guards?

Regards,
Steve

Bjorn Gustavsson wrote:
> 2009/7/23 Oscar Hellström <oscar@REDACTED>:
>> Hi Steve,
>>
>> You could also do it this way:
>>
>> transform(#rec_a{} = R) -> ... ;
>> transform(#rec_b{} = R) -> ... ;
>> ...
> 
> Yes, that is the recommended way to do it.
> 
> Not only will the matching in the function head be more efficient, but
> the compiler
> may also generate better code for further record operations in the
> body of the function.
> 
> /Bjorn
> 



More information about the erlang-questions mailing list