Hey Elan!
        This is really important info, as far as
I am concerned. The side effect is that you also
showed me how to do simple bench-marking.
I had speculated myself that char-pos1 would be
the fastest.
Thanks, and good luck with the book!
Tim
At 04:53 PM 5/17/00 -0700, you wrote:
>Hi Tim,
>
>you wrote:
>[...]
>>I would love to see some input and discussion as to what 
>>is the most efficient of the three functions. 
>[...]
>
>If you compare char-pos1 to char-pos2 then the only difference is that
>char-pos2 adds a call to found? to char-pos1. It's probably safe to
>speculate that char-pos1 should be more efficient.
>
>if you accept that, then the field is narrowed down to char-pos1 vs.
>char-pos0. You can speculate about these two, but without knowing the
>implementation details of all, any and either, the degree of confidence in
>the result of this speculation is a little lower.
>
>As a matter of principle, either accomplishes what the combined any and all
>accomplish. At face value I tend to think that char-pos1 should be more
>efficient, since it consists of one (native) function call, where the
>combination all/any requires two function calls. I doubt that any and all's
>implementations can be that much more efficient than either's
>implementation, that parsing and calling any and all would still be more
>efficient than a single parse/call to either.
>
>If you compare this speculation to some (inaccurate) measurements, I appear
>to be on the right track:
>
>>> start: now/time loop 1000000 [char-pos0 s c] print now/time - start
>0:00:46
>>> start: now/time loop 1000000 [char-pos1 s c] print now/time - start
>0:00:42
>>> start: now/time loop 1000000 [char-pos2 s c] print now/time - start
>0:00:54
>
>
>
>>I wouldn't consider readability to be an issue, because
>>this would not be a function that would need any maintenance.
>>
>>Here goes:
>>char-pos0: func [str [string!] ch [char!] /ndx]
>>[
>>  any[all [ndx: find/case str ch index? ndx] 0]
>>]
>>char-pos1: func [str[string!] ch[char!] /local result]
>>[
>>   either result: find/case str ch [index? result] [0]
>>]
>>char-pos2: func [str[string!] ch[char!] /local result]
>>[
>>   either found? result: find/case str ch [index? result][0]
>>]
>>
>>
>>
>
>;- Elan >> [: - )]
>
>

Reply via email to