[erlang-questions] Idiom for multiple case matches
Ulf Wiger
ulf@REDACTED
Fri Nov 7 18:50:06 CET 2008
Sure, it all boils down to what percentage of the computation time
is taken up by this function. Both versions are cheap, but even
normally cheap functions can be too slow sometimes.
In general, it's good advice to prefer the concise and cheap
version over the bulky but dirt-cheap. Cost-based choices at
this level should only be done after careful profiling.
BR,
Ulf W
2008/11/7 Hynek Vychodil <hynek@REDACTED>:
> There is not GC pressure by creating list in R12B because this is constant
> but there is possible pressure on the stack when looping and creting
> integers on it. May be no.
> More significant question is also which characters was used to match against
> vowels. Anyway, 80% slow down can be good reason to not use lists:member for
> me when performance is important. I think that when mostly tested characters
> which are not vowels, it can be more.
>
> On Fri, Nov 7, 2008 at 6:12 PM, Edwin Fine <erlang-questions_efine@REDACTED>
> wrote:
>>
>> Ulf,
>>
>> Isn't there also more garbage (as in GC) created by Mats' solution?
>> Doesn't the list "aeiouy" get created and destroyed every time, or does the
>> compiler "know" it is constant and make one constant copy of it that is not
>> GC'ed?
>>
>> Regards,
>> Edwin Fine
>>
>> On Fri, Nov 7, 2008 at 11:52 AM, Ulf Wiger <ulf@REDACTED> wrote:
>>>
>>> It's slower, true, but both are fairly fast*, and the lists:member/2
>>> solution is also very concise.
>>>
>>> * I ran a small benchmark. On the given machine, Robert's
>>> solution took ca 0.05 usec/call, while Mats's solution took
>>> ca 0.09 usec/call (on average, iterating 1000 over the set of
>>> vowels "aeiouyAEIOUY"). Using the smaller set "aeiouy",
>>> Robert's code still took 0.05 usec/call, while Mats's code
>>> used 0.08 usec.
>>>
>>> BR,
>>> Ulf W
>>>
>>> 2008/11/7 Hynek Vychodil <vychodil.hynek@REDACTED>:
>>> >
>>> >
>>> > On Fri, Nov 7, 2008 at 3:22 PM, mats cronqvist <masse@REDACTED>
>>> > wrote:
>>> >>
>>> >> "Robert Virding" <rvirding@REDACTED> writes:
>>> >>
>>> >> > A reasonable way of doing it would be:
>>> >> >
>>> >> > case is_vowel(Char) of
>>> >> > true -> ... ;
>>> >> > false -> ...
>>> >> > end
>>> >>
>>> >>
>>> >> is_wovel(C) -> lists:member(C,"aeiouy").
>>> >
>>> > It is slower than Robert's solution. If performance is significant
>>> > lists:member solution is worse.
>>> >>
>>> >>
>>> >> mats
>>> >> _______________________________________________
>>> >> erlang-questions mailing list
>>> >> erlang-questions@REDACTED
>>> >> http://www.erlang.org/mailman/listinfo/erlang-questions
>>> >
>>> >
>>> >
>>> > --
>>> > --Hynek (Pichi) Vychodil
>>> >
>>> > _______________________________________________
>>> > erlang-questions mailing list
>>> > erlang-questions@REDACTED
>>> > http://www.erlang.org/mailman/listinfo/erlang-questions
>>> >
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>>
>>
>
>
>
> --
> --Hynek (Pichi) Vychodil
>
More information about the erlang-questions
mailing list