[erlang-questions] The is_record() guard
Steve Davis
steven.charles.davis@REDACTED
Fri Jul 24 01:38:21 CEST 2009
Vary useful info -- thank you both Oscar and Robert.
It definitely sounds like the 'direct record match' is the most
promising answer.
If the results don't meet this expectation then I'll post comparatives
when I have some reliable numbers.
/sd
Robert Virding wrote:
> Hi Steve,
>
> 2009/7/23 Steve Davis <steven.charles.davis@REDACTED
> <mailto:steven.charles.davis@REDACTED>>
>
> Hi Oscar,
>
> Oscar Hellström wrote:
>
> You could also do it this way:
>
> transform(#rec_a{} = R) -> ... ;
> transform(#rec_b{} = R) -> ... ;
> ...
>
>
> Ah yes. Hmmm... looks like I have bought myself two possible
> refactors to try/test now ;(
>
>
> This is is a very good way of doing the test, both clean and efficient.
> It will expand the records into tuples and do ONE tuple match for them
> all. It is probably even faster than extracting the record name from the
> tuple with element/1.
>
>
>
> Not that it mattered in the end though but useless
> optimizations are very common...
>
>
> Yep, I have tried to write the code "correct" first - it was the
> fprof result that made me look at this - this match function is
> necessarily called at every invocation and is by far and away the
> slowest part of the code.
>
>
> No, using the is_record guard test is not a good way of doing it if you
> have the record definition. It might also be useful if the record is in
> the middle of a large pattern and it would be messy to write it as a
> pattern, but it is slower.
>
> Robert
>
More information about the erlang-questions
mailing list